|
先上报错:
1>源.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall CStudent::CStudent(void)" (??0CStudent@@QAE@XZ),该符号在函数 _main 中被引用
1>E:\c++daima\lianxi\Debug\lianxi.exe : fatal error LNK1120: 1 个无法解析的外部命令
以下是代码:
#include <iostream>
#include <cstring>
using namespace std;
class CStudent
{
public:
char * p_name;
int num;
CStudent();
CStudent(char* pname,int t_num);
CStudent& operator=(const CStudent& stud);
~CStudent();
};
CStudent::CStudent(char* pname,int t_num)//构造函数
{
int len=strlen(pname)+1;
p_name = new char[len];
memset(p_name,0,len);
strcpy_s(p_name,len,pname);
num=t_num;
}
CStudent& CStudent::operator=(const CStudent& stud)//运算符重载
{
if(p_name)
{
delete [] p_name;
p_name=NULL;
}
int leng =strlen(stud.p_name)+1;
if((leng-1)!=0)
{
this->p_name=new char[leng];
memset(this->p_name,0,leng);
strcpy_s(this->p_name,leng,stud.p_name);
}
num = stud.num;
return * this;
}
CStudent::~CStudent()//析构函数
{
if(p_name!=NULL)
{
delete [] p_name;
}
cout<<"没有了"<<endl;
}
int main()
{
CStudent stu1("asd",20);
CStudent stu2;
stu2 = stu1;
return 0;
} |
上一篇: 这是编译器的问题吗?下一篇: 指针数组函数的调用有问题
|