-1

I've created a class called Payload, and have a std::vector<Payload> in a class called LineShape. I've also created a function inside LineShape to get a Payload from the std::vector at a given index. This is Payload:

payload.h

class Payload {
public:

Payload (payload_type pType) {
    type = pType;
}

payload_type getPayloadType() {
    return type;
}

private:
    payload_type type;
};

and the function that is causing problems:

LineShape.h

    Payload getPayloadAt(int index) {
        return transfer.at(index);
    }

Visual Studio returns the following error:

C2334    unexpected token(s) preceding '{'; skipping apparent function body

Apparently, this means it isn't recognizing the body of the function, as a function, due to the definition of the function, but it seems okay?

EDIT: Here's the rest of the LineShape class:

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;
};`
Alaanor
  • 37
  • 1
  • 7
  • Show all of your `LineShape`. – Hatted Rooster May 31 '17 at 12:26
  • 2
    You have syntax error. – Fredrick Gauss May 31 '17 at 12:27
  • @Alaanor there is no `class` there – Ap31 May 31 '17 at 12:28
  • I don't understand the "sf::" at the beginning of the constructor – Robert Kock May 31 '17 at 12:40
  • @RobertKock `LineShape` is wrapped in a namespace of `sf`, removing it does not affect anything. – Alaanor May 31 '17 at 12:43
  • 1
    Lots of functions in there not (apparently) related to the error. Remove them - as the first step towards creating an [MCVE](https://stackoverflow.com/help/mcve) - and verify that didn't fix the problem. If the error goes away, put those functions back one at a time. If it doesn't, finish making your MCVE and post _that_ so that people can actually reproduce your problem. – Useless May 31 '17 at 12:58
  • 1
    This kind of error is often caused by something _above_ the location flagged by the compiler, and that means all `#include`d files are possibly culprits. Since you haven't _shown_ all your code, or reduced your code to the minimum that reproduces the problem, no-one can tell you what the cause is, except that it's not immediately visible in your question. – Useless May 31 '17 at 13:02
  • @Useless, You're right, indeed it was a `#include` problem. I had included `LineShape.h` in `payload.h`, and was never using it in `payload.h`, after removing it, everything ran fine. Can someone fill me in on why this could possibly cause problems like this? – Alaanor May 31 '17 at 13:20
  • Are you using include guards? They're a standard way of avoiding circular include problems. – Useless May 31 '17 at 13:26
  • I do not use include guards, but I should probably start doing so. – Alaanor May 31 '17 at 13:32

1 Answers1

0

It seems like there is a '`' at the end of your Lineshape Class after the semicolon, but maybe that one just comes from bad copy pasting.

nils
  • 338
  • 2
  • 11