C++ C++;:未定义引用

C++ C++;:未定义引用,c++,undefined-reference,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

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.o: In function `window::setmove(int)':
/afs/cats.ucsc.edu/users/m/graphics.h:72: undefined reference to `window::move'
这很奇怪,因为在interp.cpp内的另一个函数中,我可以使用
window::push_back(新的_形状)

你知道会出什么问题吗?多谢各位


编辑:因为它被标记为重复:我不认为这是一个编译器问题,因为我可以使用window类中的其他函数。

C++需要为静态成员定义。在
interp.cpp
中定义静态变量
move
,可以解决此问题。您需要添加
static int window::move


感谢:MattMcNabb和juanchopanza的评论。

您是否能够在
interp.cpp
中访问其他函数
setwidth
setheight
?是的,我能够在interp.cpp中访问这两个函数。@juanchopanza我不同意重复的标记。“复制”是一个巨大的文章,涵盖了几个不同的问题,所有这些都导致相同的错误信息,可能是不清楚的经验不足的C++编码器哪一个applies@Raymond错误出现在
window::move
中。你从未定义过它。当您编写
静态int-move时这是一个声明,但不是定义。您还必须在.cpp文件中为其提供定义:
static int window::move。这适用于所有静态变量和函数。函数可以内联定义;在一些情况下,变量可以内联定义。@MattMcNabb也许这一个更有用:我会看看是否可以更改它。注释和标记为重复就足够了@πάνταῥεῖ : 我不知道评论是否足够,不需要回答。谢谢你让我知道这件事。我也觉得评论已经足够了。但我看到的答案(现在还没有)很少有误导性。所以我想我可以通过提及评论员和答案来帮助读者。
interp.o: In function `window::setmove(int)':
/afs/cats.ucsc.edu/users/m/graphics.h:72: undefined reference to `window::move'