c++初学者,问大神们一个问题

qq_26296715 2015-05-02 10:13:58
#include<iostream>
#include<string>
using namespace std;
class Date
{
public:
Date(int y=0,int m=0,int d=0);
~Date()
{cout<<"Destructor called."<<endl;}

int year;
int month;
int day;
};
Date::Date(int y,int m,int d)
{
year=y;
month=m;
day=d;
}
Date::Date(const Date& b)
{
year=b.year;
month=b.month;
day=b.day;
}
class People
{
public:
People(string,string,int,int,int,int);
~People()
{cout<<"Destructor called."<<endl;}
void show();
void set();
private:
string name;
string sex;
Date birthday;
int id;
};
People::People(string n,string s,int y,int m,int d,int i):birthday(y,m,d)
{
name=n;
sex=s;
id=i;
}
People::People(const People& b)
{
name=b.name;
sex=b.sex;
Date birthday(b.birthday);
id=b.id;
}
void People::show()
{
cout<<"name "<<name<<endl<<"sex "<<sex<<endl<<"birthday"<<birthday.year <<birthday.month <<birthday.day <<endl<<"id" <<id<<endl;
}
void People::set()
{
cin>>name>>sex>>birthday.year>>birthday.month>>birthday.day>>id;
}
int main()
{
People p1("bb","man",1992,12,01,5684554654);
People p2("cc","man",1996,11,02,6456456454);
People p2(p1);
return 0;
}
提示
1>e:\调试\preject_1\preject_1\test1.cpp(22): error C2600: “Date::Date”: 不能定义编译器生成的特殊成员函数(必须首先在类中声明)
1>e:\调试\preject_1\preject_1\test1.cpp(48): error C2600: “People::People”: 不能定义编译器生成的特殊成员函数(必须首先在类中声明)

错在哪儿啊,不明白,求大神们帮助。
...全文
130 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_26296715 2015-05-03
  • 打赏
  • 举报
回复
谢谢大神,非常感激
苏叔叔 2015-05-02
  • 打赏
  • 举报
回复
修改如下:

#include<iostream>
#include<string>
using namespace std;
class Date
{
public:
	Date(int y = 0, int m = 0, int d = 0);
	Date(const Date& b);
	~Date()
	{
		cout << "Destructor called." << endl;
	}

	int year;
	int month;
	int day;
};
Date::Date(int y, int m, int d)
{
	year = y;
	month = m;
	day = d;
}
Date::Date(const Date& b)
{
	year = b.year;
	month = b.month;
	day = b.day;
}
class People
{
public:
	People(string, string, int, int, int, int);
	People(const People& b);
	~People()
	{
		cout << "Destructor called." << endl;
	}
	void show();
	void set();
private:
	string name;
	string sex;
	Date birthday;
	int id;
};
People::People(string n, string s, int y, int m, int d, int i) :birthday(y, m, d)
{
	name = n;
	sex = s;
	id = i;
}
People::People(const People& b)
{
	name = b.name;
	sex = b.sex;
	Date birthday(b.birthday);
	id = b.id;
}
void People::show()
{
	cout << "name " << name << endl << "sex " << sex << endl << "birthday" << birthday.year << birthday.month << birthday.day << endl << "id" << id << endl;
}
void People::set()
{
	cin >> name >> sex >> birthday.year >> birthday.month >> birthday.day >> id;
}
int main()
{
	People p1("bb", "man", 1992, 12, 01, 5684554654);
	People p2("cc", "man", 1996, 11, 02, 6456456454);
	People p3(p1);
	return 0;
}
aillis 2015-05-02
  • 打赏
  • 举报
回复
你的两类的赋值函数没有在类中声明,你声明一下就可以了.

64,666

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧