"Type" does not refer to a value on C++

16,432

Solution 1

This error is also caused if you call a static method using dot(.) operator instead of scope(::) operator.

Solution 2

OP here - In my case, the error happened due to not closing the method properly, the Canvas::createStuff() was missing "}".

Solution 3

Don't much more without looking at the whole of it, but off the top of my head, C++ compilers will cascade variable names as undeclared if their types are also undeclared, although you may see on out there assuming that the typeless variable is an int, leading to all sorts of goofiness.

Beyond that, check to see if ofVec2 is being included by what you have, and see what namespace it is in. Like, if ofVec2f is in some namespace, you will either need to do using namespacename; or, morepreferrably, refer to ofVec2f with its namespace prefix.

Share:
16,432
cleliodpaula
Author by

cleliodpaula

Updated on June 17, 2022

Comments

  • cleliodpaula
    cleliodpaula almost 2 years

    I'm getting this error at OpenFrameworks artwork. But appears to be a simple C++ issue.

    ofVec2f does not refer to a value
    

    Certainly I'm having problems with pointers, but I could't understand why. I tried to change & -> *

    canvas4.cpp

    void Canvas4::createStuff() {
        ballCollection.clear();
        for (int i=0; i<num; i++) {
            ofVec2f org;
            org.set(ofRandom(edge, ofGetWidth()-edge), ofRandom(edge, ofGetHeight()-edge));
            float radius = ofRandom(50, 150);
            ofVec2f loc;
            loc.set(org.x+radius, org.y);
            float offSet = ofRandom(TWO_PI);
            int dir = 1;
            float r = ofRandom(1);
            if (r>.5) dir =-1;
            myBall = new Ball(org, loc, radius, dir, offSet);
            ballCollection.push_back(* myBall);
        }
    
    //
    

    This is the constructor of Ball class;

    Ball::Ball(ofVec2f &_org, ofVec2f &_loc, float _radius, int _dir, float _offSet) {
    // **** error occur right here.
    // use of undeclared "_org"
        org = _org;
        loc = _loc;
        radius = _radius;
        dir = _dir;
        offSet = _offSet;
    }
    

    Header Canvas4.h

    class Ball {
    public:
        ofVec2f org;
        ofVec2f loc;
        float sz = 10;
        float theta, radius, offSet;
        int s, dir, d = 60;
    
        Ball(ofVec2f &_org, ofVec2f &_loc, float _radius, int _dir, float _offSet);
    
    
    };
    
    
    class Canvas4{
    public:
        int fc = 100;
        int num = 100;
        int edge = 200;
        vector<Ball> ballCollection;
        Boolean save = false;
        ofFbo fbo;
        Ball *myBall;
    
        Canvas4();
    
    
    };