我创建了一个名为 的类Payload
,并std::vector<Payload>
在一个名为LineShape
. 我还在里面创建了一个函数来从给定索引处LineShape
获取 a 。这是:Payload
std::vector
Payload
有效载荷.h
class Payload {
public:
Payload (payload_type pType) {
type = pType;
}
payload_type getPayloadType() {
return type;
}
private:
payload_type type;
};
以及导致问题的功能:
线形.h
Payload getPayloadAt(int index) {
return transfer.at(index);
}
Visual Studio 返回以下错误:
C2334 unexpected token(s) preceding '{'; skipping apparent function body
显然,这意味着由于函数的定义,它没有将函数的主体识别为函数,但看起来还可以吗?
编辑:这是课程的其余部分LineShape
:
class LineShape {
public:
sf::LineShape(sf::Vector2f i_point1, sf::Vector2f i_point2, float i_thickness = 5) {
point1 = i_point1;
point2 = i_point2;
thickness = i_thickness;
vertArr.setPrimitiveType(sf::LinesStrip);
vertArr.resize(2);
vertArr[0].position = point1;
vertArr[1].position = point2;
updateShape();
}
void updateShape() {
float sX = point1.x - point2.x;
float sY = point1.y - point2.y;
float sX2 = pow(sX, 2);
float sY2 = pow(sY, 2);
float sD = abs(sqrt(sX2 + sY2));
float shapeAngle_rad = std::atan2(sY, sX);
float shapeAngle = shapeAngle_rad * 180 / PI;
float shapeLength = sf::length(sf::Vector2f(point2 - point1));
arrShape.setSize(sf::Vector2f(shapeLength, thickness));
arrShape.setPosition(point2);
arrShape.setRotation(shapeAngle);
}
sf::Vector2f getPointPosition(sf::pointNum targetPoint) {
switch (targetPoint) {
case sf::pointNum::point1: {
return point1;
}
case sf::pointNum::point2: {
return point2;
}
};
}
void setPointPosition(sf::pointNum targetPoint, sf::Vector2f position) {
switch (targetPoint) {
case sf::pointNum::point1: {
point1 = position;
}
case sf::pointNum::point2: {
point2 = position;
}
};
updateShape();
}
void setColor(sf::Color color) {
arrShape.setFillColor(color);
}
void setOutlineColor(sf::Color color) {
arrShape.setOutlineColor(color);
}
void setOutlineWidth(float width) {
arrShape.setOutlineThickness(width);
}
void draw(sf::RenderWindow &window) {
window.draw(arrShape);
}
// PAYLOADS
void addPayload(Payload payload, bool through_filter = true) {
if (through_filter) {
if (payload.getPayloadType() == transferFilter) {
transfer.push_back(payload);
}
else {
G_LOG::INCORRECT_ITEM_PASSED_TO_FILTER();
};
}
else {
transfer.push_back(payload);
};
}
Payload getPayloadAt(int index) {
return transfer.at(index);
}
std::vector<Payload> getTransfer() {
return transfer;
}
void setPayloadFilter(payload_type filter) {
transferFilter = filter;
}
private:
sf::VertexArray vertArr;
sf::RectangleShape arrShape;
std::vector<Payload> transfer;
payload_type transferFilter;
sf::Vector2f point1;
sf::Vector2f point2;
float thickness;
};`