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

有关类的一些问题请大家指教啊

方程式 发布于 2004-07-16 02:17, 1200 次点击

写个小程序如下: #include <iostream.h> class XXX { private : int a; int b; public: XXX(); void w(int,int); void s(); };

void XXX::w(int x,int y) { a=x;b=y; } void XXX::s() { cout <<"\n"<<a<<"\n"<<b; } void main() { XXX n; int a,b; cout<<"input a,b:"; cin >> a>>b; n.w(a,b); n.s();

} 编译通过了,但按F7后出现如下错误: -------------------Configuration: 6 - Win32 Debug-------------------- Compiling... 6.cpp Linking... 6.obj : error LNK2001: unresolved external symbol "public: __thiscall XXX::XXX(void)" (??0XXX@@QAE@XZ) Debug/6.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe.

6.exe - 2 error(s), 0 warning(s) 请指教一下!!!

4 回复
#2
C++大粉丝2004-07-16 08:54

你的构造函数没有实现.

XXX:XXX(){}

#3
kuangjingbo2004-07-17 20:07

楼上说的对,你只声明了构造函数,但是没有实现

#4
kai2004-07-20 04:33

#include <iostream.h>

class XXX { private : int a; int b; public: XXX(){} // when the default constructor don't manipulate the date, then you need not write it // the compiler will do it automatic for you. void w(int,int); void s(); };

void XXX::w(int x,int y) { a=x;b=y; }

void XXX::s() { cout <<"\n"<<a<<"\n"<<b; }

int main() { XXX n; int a,b; cout<<"input a,b:"; cin >> a>>b; n.w(a,b); n.s(); return 0;

}

#5
金多虾2009-08-04 21:54
构造函数没有进行功能的实现!
1