注册 登录
编程论坛 C++教室

error LNK2001

独孤剑魔 发布于 2008-10-15 15:19, 677 次点击
一下是原题:
typedef string Type;
Type initVal();
class Exercise
{
public:
    typedef double Type;
    Type setVal(Type);
    Type initVal();
private:
    int val;
};
Type Exercise::setVal(Type parm)
{
         val = parm+initVal();
}


这是我更改后的:
typedef string Type;
Type initVal();
class Exercise
{
public:
    typedef double Type;
    Type setVal(Type);
    Type initVal();
private:
    int val;
};
Exercise::Type Exercise::setVal(Exercise::Type parm)
{
    val = parm+Exercise::initVal();
    return val;
}


一下是错误消息
--------------------Configuration: new1 - Win32 Debug--------------------
Compiling...
new1.cpp
Linking...
new1.obj : error LNK2001: unresolved external symbol "public: double __thiscall Exercise::initVal(void)" (?initVal@Exercise@@QAENXZ)
Debug/new1.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

new1.exe - 2 error(s), 0 warning(s)
1 回复
#2
独孤剑魔2008-10-15 15:20
关于那个initVal()函数,我已经加上了::,指明使用类中的,为什么会这样?
1