我创建了一个名为Payload
的课程,并在名为std::vector<Payload>
的课程中设置了LineShape
。我还在LineShape
内创建了一个函数,以便在给定索引处从Payload
获取std::vector
。这是Payload
:
payload.h
class Payload {
public:
Payload (payload_type pType) {
type = pType;
}
payload_type getPayloadType() {
return type;
}
private:
payload_type type;
};
以及导致问题的功能:
LineShape.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;
};`
答案 0 :(得分:0)
似乎有一个&#39;`&#39;在分号后的Lineshape类的末尾,但也许那个只是来自糟糕的复制粘贴。