Question

There are a lot of topics on Use of undeclared identifier but none are helping me. Most of them are for ios development, and i'm probably to noobie to understand.

this is my header (stripped down to the problem):

#pragma once

#include "ofMain.h"

class ImageRayTracer {

    public:
        // empty constructor
        ImageRayTracer(void);
        void setHitColor(ofColor c);

    private:
        ofColor hitColor;
};

this is my implementation stripped down to the problem:

#include "imageRayTracer.h"


ImageRayTracer::ImageRayTracer(void) {
    hitColor.set(0);
}


// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

void setHitColor(ofColor c) {
    //Use of undeclared identifier
    hitColor = c;
}

I have no problem in the constructor but i have a problem in the setHitColor method. Why is this? And how to resolve?

Was it helpful?

Solution

void setHitColor(ofColor c) {
    //Use of undeclared identifier
    hitColor = c;
}

tries to define a function within global scope. This function tries to assign argument c to unknown (undeclared) hitColor. To define a member function you must prefix it with name of the class so that compiler will be able to associate it with the definition of your class:

void ImageRayTracer::setHitColor(ofColor c) {
    //Use of undeclared identifier
    hitColor = c;
}

OTHER TIPS

You have to say that setHitColor() is a method of ImageRayTracer, like you did with the constructor.

void ImageRayTracer::setHitColor(ofColor c) {
    //Use of undeclared identifier
    hitColor = c;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top