【发布时间】:2012-06-04 11:32:10
【问题描述】:
我在使用 C++ 的以下代码中遇到错误。
Main.cpp
#include "file.h"
int main()
{
int k = GetInteger();
return 0;
}
文件.h
static int GetInteger();
文件.cpp
#include "file.h"
static int GetInteger()
{
return 1;
}
我得到的错误:
Error C2129: static function 'int GetInteger(void)' declared but not defined.
我看过著名的文章"Organizing Code File in C and C++",但不明白这段代码有什么问题。
【问题讨论】:
-
你如何链接它? "gcc -o Test Main.cpp File.cpp -lstdc++" 或 XCode/VisualStudio/Eclipse 中的某处?
-
@ViktorLatypov 说了什么。向我们展示你是如何编译它的。
-
@ViktorLatypov:我在 C++/CLI 项目中选择 Visual Studio 2013 中的文件并单击编译按钮时遇到了这个问题。 (C++ 按钮的编译按钮没有链接,也不应该遇到此错误,但也许 C++/CLI 不同?)(哦等等,刚刚看到最佳答案。我已将
static类转换为命名空间>.
标签: c++ static-methods