c++ - 在 openframeworks 中使用未声明的标识符

标签 c++ openframeworks

有很多关于使用未声明标识符的主题,但没有一个对我有帮助。 其中大部分是针对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/

相关文章:

c++ - "structural binding"上的提案在哪里?

c++ - 为什么 CMake 被设计为在安装时删除运行时路径

c++ - 更新功能中的跳跃 Action 播放声音(openframework)

opencv - 使用OpenCV进行镜头检测

ios - Openframeworks iOS 项目 : texture on ofSpherePrimitive breaks

c++ - 返回 const 值以利用 move 语义与防止诸如 (a+b)=c 之类的东西

c++ - 为什么不在这个静态库中创建多个已定义的符号?

c++ - MFC web浏览器控件中禁用键盘快捷键的方法

opengl - 保存大于窗口的openGL FBO的问题

linux - git 总是强制更改文件