帮忙看一下,我调试不过去,是什么问题?谢了。
//AppMain.cpp
#include <iostream>
#include"Tdate.h"
#include"People.h"
#include"in_out.h"
void main()
{
people p1;
p1.output();
p1.input();
p1.output();
people p2(p1);
cout<<"another people..."<<endl;
p2.output();
}
//Tate.h
class Tdate
{
public:
Tdate(int m=1,int d=0,int y=1995)
{
month=m;day=d;year=y;
}
int &getm(){return month;}
int &getd(){return day;}
int &gety(){return year;}
protected:
int month;int day;int year;
};
//People.h
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=0,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.gety()=p.birthday.gety();
birthday.getm()=p.birthday.getm();
birthday.getd()=p.birthday.getd();
cout<<"copy..."<<endl;
}
//in_out.h
void output()
{
cout<<"the information of pleple:"<<endl;
cout<<"number"<<number<<endl;
cout<<"sex"<<sex<<endl;
cout<<"id"<<id<<endl;
cout<<"birthday"<<birthday.gety()<<"--"<<birthday.getm()<<"--"
<<birthday.getd()<<endl;
}
people(people &p);
~people(){cout<<"析构..."<<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();
}
请那位大哥指点一下是那没写对。导致编译不过去。
问题点数:50、回复次数:12Top
1 楼heskyII(赫斯基)回复于 2005-02-03 21:07:53 得分 0
在CLASS PEOPLE中i是int类型,其长度最多在-32768到32767(UNSIGNED INT 是0到65535)范围内
其他的还正在看
Top
2 楼heskyII(赫斯基)回复于 2005-02-03 21:15:58 得分 0
虽然你有Tdate类类型的定义,但在类PEOPLE中Tdate并不能被识别到,编译也会报错
除非你把所有有关连的头文件都定义在一个.H中,然后再#INCLUDE到MAIN函数里,进行编译Top
3 楼heskyII(赫斯基)回复于 2005-02-03 21:40:20 得分 25
应该是People::input(){......}
对类中私有对象有使用全限的只能是该类中的成员函数,有其他方式可以调用,但很繁琐.
Top
4 楼pdaliu(刘星)回复于 2005-02-03 22:13:55 得分 0
using namespace std;
写上这个呢?好像不写这个cout不能用的!Top
5 楼pdaliu(刘星)回复于 2005-02-03 22:20:20 得分 0
people(people &p);
~people(){cout<<"析构..."<<endl;};
这样写行吗?好像要加pepole::吧?是不是啊?~~我刚学类的!Top
6 楼sharuxing(寻圆)回复于 2005-02-03 22:30:59 得分 0
using namespace std;
写上也不行啊。。。。
--------------------Configuration: - Win32 Debug--------------------
Compiling...
AppMain.cpp
people.h(13) : error C2511: 'people::people' : overloaded member function 'void (class people &)' not found in 'people'
我理解好像是提示,people类的拷贝构造函数people有问题。不知道出在什么地方上了。
Top
7 楼pdaliu(刘星)回复于 2005-02-03 22:41:32 得分 0
heskyII(赫斯基)
int它的范围和机器有关(好像是这样!要不就是和编译器有关)!我的int型占4个字节!-32768~32767是占2个字节Top
8 楼pdaliu(刘星)回复于 2005-02-03 22:45:30 得分 0
那我也说不上了~...
你最好把他们都放到一个文件里编译一下!(当然这是一个笨方法~)Top
9 楼pdaliu(刘星)回复于 2005-02-03 22:50:28 得分 0
再多问一下~这是什么用处啊?输入生日的?Top
10 楼zjyu88(刚步入三流大学)回复于 2005-02-03 23:32:13 得分 25
你在people类里都没定义它的拷贝构造函数..
奇怪的是people的析构函数写在in_out.h里...而且在people里也没定义析构函数.Top
11 楼sharuxing(寻圆)回复于 2005-02-03 23:35:13 得分 0
是啊。。。用来输人的生日Top
12 楼sharuxing(寻圆)回复于 2005-02-04 01:31:29 得分 0
people成员函数input(),output()写错地方了,应该定义在people类里面的publc成员里面,这样主程序才能调用的了。
修改如下:
//AppMain.cpp
#include <iostream>
using namespace std;
#include"Tdate.h"
#include"People.h"
void main()
{
people p1;
p1.output();
p1.input();
p1.output();
people p2(p1);
cout<<"another people..."<<endl;
p2.output();
}
//Tdate.h
class Tdate
{
public:
Tdate(int m=1,int d=0,int y=1995)
{
month=m;day=d;year=y;
}
int &getm(){return month;}
int &getd(){return day;}
int &gety(){return year;}
protected:
int month;int day;int year;
};
//People.h
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=0,int y=1995):birthday(m,d,y)
{number=n;sex=s;id=i;}
void output()
{
cout<<"the information of pleple:"<<endl;
cout<<"number "<<number<<endl;
cout<<"sex "<<sex<<endl;
cout<<"id "<<id<<endl;
cout<<"birthday "<<birthday.gety()<<"--"<<birthday.getm()<<"--"
<<birthday.getd()<<endl;
}
people(people &p);
~people(){cout<<"析构..."<<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();
}
};
people::people(people &p)
{
number=p.number;
sex=p.sex;
id=p.id;
birthday.gety()=p.birthday.gety();
birthday.getm()=p.birthday.getm();
birthday.getd()=p.birthday.getd();
cout<<"copy..."<<endl;
}
谢谢各位帮助。
Top




