主题:新手求解
#include<iostream>
using namespace std;
class cow
{
char name[20];
char *hobby;
double weight;
public:
cow();
cow(const char *nm,const char*ho,double wt);
cow(const cow&);
~cow();
cow & operator=(const cow &);
void showcow()const;
};
cow::cow(const char* nm,const char*ho,double wt)
{
strcpy(name,nm);
strcpy(hobby,ho);
weight=wt;
}
cow::cow(const cow &b)
{
strcpy(name,b.name);
strcpy(hobby,b.hobby);
weight=b.weight;
}
cow & cow::operator=(const cow &c)
{
strcpy(name,c.name);
strcpy(hobby,c.hobby);
weight=c.weight;
return *this;
}
void cow::showcow()const
{
cout<<name<<endl;
cout<<hobby<<endl;
cout<<weight<<endl;
}
cow::~cow(){};
cow::cow(){};
void main()
{
cow xx("ck","fung",22);
xx.showcow();
cow xxx("ao","ko",222);
xxx.showcow();
xx=cow("bb","cc",44);
xx.showcow();
xx=xxx;
xx.showcow();
}
调试时停止工作,,求解,,用的是visual studio2010;
using namespace std;
class cow
{
char name[20];
char *hobby;
double weight;
public:
cow();
cow(const char *nm,const char*ho,double wt);
cow(const cow&);
~cow();
cow & operator=(const cow &);
void showcow()const;
};
cow::cow(const char* nm,const char*ho,double wt)
{
strcpy(name,nm);
strcpy(hobby,ho);
weight=wt;
}
cow::cow(const cow &b)
{
strcpy(name,b.name);
strcpy(hobby,b.hobby);
weight=b.weight;
}
cow & cow::operator=(const cow &c)
{
strcpy(name,c.name);
strcpy(hobby,c.hobby);
weight=c.weight;
return *this;
}
void cow::showcow()const
{
cout<<name<<endl;
cout<<hobby<<endl;
cout<<weight<<endl;
}
cow::~cow(){};
cow::cow(){};
void main()
{
cow xx("ck","fung",22);
xx.showcow();
cow xxx("ao","ko",222);
xxx.showcow();
xx=cow("bb","cc",44);
xx.showcow();
xx=xxx;
xx.showcow();
}
调试时停止工作,,求解,,用的是visual studio2010;