我按教程的输入了下面的程序:
(是个练习类组合的一个东东,在编译的时候,出现了问题,加上using namespace std;这句的话,说error C2871: 'std' : does not exist or is not a namespace,不加这句的话,说error C2676: binary '<<' : 'class istream_withassign' does not define this operator or a conversion to a type acceptable to the predefined operator,我英文也不好,看不懂是啥意思,是不是程序在玩我啊?我想是我在什么地方弄错了的,哈哈,不过我真的找不到了,请高手帮我测试一下,然后把改后的程序再复制上来哟,谢过!(这个问题已经解决)
另一个问题是:程序连接完后,.exe文件居然536KB,为什么会这么大呢?我感觉很奇怪的。。。
我认为要是在50K以内的话,才能算正常的吧,请高手指教。
#include<iostream.h>
class Tdate
{
public:
Tdate(int m=1,int d=1,int y=1995)
{
month=m;
day=d;
year=y;
}
int &getm(){return month;}
int &getd(){return day;}
int &gety(){return year;}
private:
int month;
int day;
int year;
};
class People
{
private:
int number;
char sex;
int id;
Tdate birthday;
public:
People(int n=0,char s='m',int i=32000000,int m=1,int d=1,int y=1995)
:birthday(m,d,y)
{
number=n;
sex=s;
id=i;
}
People::People(People &p)
{
number=p.number;
sex=p.sex;
id=p.id;
birthday.getm()=p.birthday.getm();
birthday.getd()=p.birthday.getd();
birthday.gety()=p.birthday.gety();
cout<<"copy..."<<endl;
}
void input()
{
cout<<"\n input number:";
cin<<number;
cout<<"\n input sex:";
cin<<sex;
cout<<"\n input id:";
cin<<id;
cout<<"\n input year of birthday:";
cin<<birthday.gety();
cout<<"\n input month of birthday:";
cin<<birthday.getm();
cout<<"\n input day of birthday:";
cin<<birthday.getd();
}
void output()
{
cout<<"The information people:"<<endl;
cout<<"number "<<number<<endl;
cout<<"sex "<<sex<<endl;
cout<<"id "<<id<<endl;
cout<<"birthday "<<birthday.getm()<<"--"<<birthday.getd()<<"--"<<birthday.gety()<<endl;
}
~People(){cout<<"析构。。。"<<endl;}
};
void main()
{
People p1;
p1.output();
p1.input();
p1.output();
People p2(p1);
p2.output();
}
[此贴子已经被作者于2006-11-5 7:57:11编辑过]