【发布时间】:2011-06-05 10:39:38
【问题描述】:
我在 Global.h 中定义了这个类
class Global
{
public:
static string InttoStr(int num);
};
在 Global.cpp 中,我有
Global::InttoStr(int num)
{
//Code To convert integer into string.
}
现在,在 SubMove.cpp 中,当我调用 Global::InttoStr(num) 时出现以下错误:
错误 LNK2019:未解析的外部符号 Global::InttoStr(int) 在函数 SubMove::toString(void) 中引用
然后我将函数设为非静态并这样调用它:
Global g;
g.InttoStr(num);
但错误仍然存在。
我认为它与外部有关并进行了搜索,但我无法建立任何联系。请帮忙。
【问题讨论】:
-
你能粘贴更多相关的代码吗?从您的描述中很难想象问题可能是什么。例如,"Global::InttoStr(int num) { ..." 看起来不应该编译。
-
您在 Global.cpp 中的定义缺少返回值。这是代码的编写方式,还是只是问题中的拼写错误?
-
如何编译?
gcc SubMove.cpp?您需要包含两个 .cpp 文件。
标签: function static call external member