有很多关于使用未声明标识符的主题,但没有一个对我有帮助。 其中大部分是针对ios开发的,我可能是菜鸟无法理解的。
这是我的标题(精简到问题):
#pragma once
#include "ofMain.h"
class ImageRayTracer {
public:
// empty constructor
ImageRayTracer(void);
void setHitColor(ofColor c);
private:
ofColor hitColor;
};
这是我针对问题的实现:
#include "imageRayTracer.h"
ImageRayTracer::ImageRayTracer(void) {
hitColor.set(0);
}
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
void setHitColor(ofColor c) {
//Use of undeclared identifier
hitColor = c;
}
我在构造函数中没有问题,但在 setHitColor 方法中遇到问题。 为什么是这样?又该如何解决?
最佳答案
void setHitColor(ofColor c) {
//Use of undeclared identifier
hitColor = c;
}
尝试在全局范围内定义一个函数。此函数尝试将参数 c
分配给未知(未声明)的 hitColor
。要定义成员函数,您必须在其前面加上类名,以便编译器能够将其与类的定义关联起来:
void ImageRayTracer::setHitColor(ofColor c) {
//Use of undeclared identifier
hitColor = c;
}
关于c++ - 在 openframeworks 中使用未声明的标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19370256/