문제

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?

도움이 되었습니까?

해결책

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;
}

다른 팁

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;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top