注册 登录
编程论坛 C++教室

写好了一个关于People的类然后代码没错,这个是什么错了

zhanyuxing 发布于 2012-11-23 14:24, 505 次点击
#include<iostream>
#include<string>
using namespace std;

class Date{
public:
    Date(char brithday[12])
{   cout<<"类内嵌子对象被调用"<<endl;
    cout<<"brithday is"<<brithday[12]<<endl;}
};
class People{
private:
       int number;
       char sex[4];
       char *id;
public:
    Date a(char a[12]);//类内嵌子对象
    People(int a,char s[4],char *i);
    void print();
    ~People();
};

    People::People(int a,char s[4],char *i)//定义了一个对象成员函数
    {   number=a;
        sex[4]=s[4];
        id=new char [strlen(i)+1];
        strcpy(id,i);
        cout<<"对象成员函数被调用"<<endl;
    }

    void People::print(){cout<<number<<sex[4]<<*id;}

    void main()
    {int b;//输入编号a的值
    char k[4];//性别sex
    char m[12];//brithday
    char l[20];//身份证ID
    cin>>b;
    cin>>k;
    cin>>l;
    cin>>m;
    People(b,k,l);

    Date::Date (m);
    }
8 回复
#2
TonyDeng2012-11-23 14:29
要给你转过去C++区吗?
#3
rjsp2012-11-23 14:57
看这标题,转C++区也不合适呀
转到体育区吧,让体育老师重教中文

“代码没错,这个是什么错了”
------ 代码没错,你还问个球呀?无论是语法还是逻辑都含在代码中。“是什么错了”应当是你告诉别人,编译不通过,别人帮你改语法错误;运行不符合预期,别人帮你改逻辑错误。
#4
TonyDeng2012-11-23 14:58
呵呵,转过来给你们定夺。
#5
a6359580002012-11-23 15:09
#include<iostream>
#include<string>
using namespace std;

class Date{
public:
    Date(char brithday[12])
{   cout<<"类内嵌子对象被调用"<<endl;
    cout<<"brithday is"<<brithday<<endl;}
};
class People{
private:
       int number;
       char sex[4];
       char *id;
public:
    Date a(char a[12]);//类内嵌子对象
    People(int a,char s[4],char *i);
    void print();
    ~People();
};
 People::~People()
 {cout<<"析构函数被调用"<<endl;}

People::People(int a,char s[4],char *i)//定义了一个对象成员函数
    {   number=a;
        sex[4]=s[4];
        id=new char [strlen(i)+1];
        strcpy(id,i);
        cout<<"对象成员函数被调用"<<endl;
    }

    void People::print(){cout<<number<<sex[4]<<*id;}

    void main()
    {int b;//输入编号a的值
    char k[4];//性别sex
    char m[12];//brithday
    char l[20];//身份证ID
    cin>>b;
    cin>>k;
    cin>>l;
    cin>>m;
    People::People(b,k,l);

    Date::Date (m);
    }
改好了,你看看
#6
mmmmmmmmmmmm2012-11-23 15:37
楼主 一起学习 加油
#7
yang829101312012-11-23 16:44
回复 5楼 a635958000
弱问一句 析构函数一定要加“{ /*函数体*/  }”吗  可以不可以只有~PEOPLE()
#8
zhanyuxing2012-11-23 17:50
回复 4楼 TonyDeng
还是不行。这个有问题。
#9
a6359580002012-11-26 10:27
回复 7楼 yang82910131
你需要声明一下析构函数啊,函数体内可以为空语句啊。
1