c++:未定义引用
C++ : Undefined reference
In: graphics.h:
class window {
friend class mouse;
private:
static int width; // in pixels
static int height; // in pixels
static vector<object> objects;
static size_t selected_obj;
static mouse mus;
static int move;
public:
static void setmove (int move_) { window::move = move_; } //<--- problem
static void push_back (const object& obj)
{ objects.push_back (obj); }
static void setwidth (int width_) { width = width_; }
static void setheight (int height_) { height = height_; }
static void main();
};
在一个名为interp.cpp的类中的函数中:我正在尝试这样做:
window::setmove(4);
但遗憾的是,我得到了这个错误:
interp.o: In function `window::setmove(int)':
/afs/cats.ucsc.edu/users/m/graphics.h:72: undefined reference to `window::move'
这很奇怪,因为在inter。cpp中的另一个函数中,我可以使用window::push_back(new_shape);
你知道有什么问题吗?谢谢你。
编辑:因为它被标记为重复:我不知道它如何可能是一个编译器问题,因为我能够使用窗口类内的其他函数。
c++需要静态成员的定义。在interp.cpp
中定义静态变量move
可以解决这个问题。您需要在inter .cpp中添加static int window::move;
。
感谢:MattMcNabb和juanchopanza的评论。
相关文章:
- 编译C++时未定义的引用
- 如何修复此错误:未定义对"距离(浮点数,浮点数,浮点数,浮点数,浮点数)"的引用
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 对C宏的未定义引用,但在定义它时会出现重新定义错误
- 未定义的引用在哪里
- 编译时的 CImg 库返回对"__imp_SetDIBitsToDevice"的未定义引用
- 对Py_Initialize()的未定义引用
- 使用mysql c++连接器的未定义引用
- 未定义的引用 .. 使用 OpenCV 编译 C++ 代码时,从命令行
- 对 Scalar ::Scalar() 的未定义引用
- 已定义函数时出现 G++ "未定义的引用"错误
- 链接 cmake 时出现未定义的引用错误
- 对复制 CTOR 和 CTOR 的未定义引用
- 错误:未定义对'oboe::AudioStreamBuilder::openStream(oboe::AudioStream**)'的引用
- 右值引用未定义的行为
- 对"vtable for DigitalClock"的未定义引用 - 未定义对"DigitalClock::staticMetaObject"的引用 - Qt
- 函数类型到函数类型的引用:未定义的引用
- avcodec_alloc_context引用未定义,但ffmpeg链接顺序正确
- 从c++调用Fortran子程序,链接时引用未定义
- 枚举引用未定义,但位于包含的头文件中