问题

无敌剑脑 发布于 2018/06/23 15:42
阅读 60
收藏 0

#include <iostream>
using namespace std;
class Person
{
    char Xing[4];
    int Old;
    char *Name;
public:
    Person(char *pX,int o,char *pName)
    {
        strcpy(Xing,pX);
        Old=o;
        int len=strlen(pName);
        if(len<=0)   
            Name=0;
        else
        {
            Name=new char[len+1];
            strcpy(Name,pName);
        }
    }
    int getx()
    {    return Xing[4];   }
    int geto()
    {    return Old;    }
    void show()
    {
        cout<<"姓名:"<<Name<<" 性别:"<<Xing<<" 年龄:"<<Old<<endl;
    }
    ~Person()
    {
        delete []Name;
    }
};
class Student:public Person
{
public:
    char ID[10];
    char *Ban;
    Student(char *pX,int O,char *pName,char *pID,char *pBan):Person(char *pX,int O,char *pName)
    {
        strcpy(ID,pID);
        int len=strlen(pBan);
        if(len<=0)   
            Ban=0;
        else
        {
            Ban=new char[len+1];
            strcpy(Ban,pBan);
        }
    }
    void show()
    {
        Person::show();
        cout<<"学号:"<<ID<<" 班级:"<<Ban<<endl;
    }
    ~Student()
    {
        delete []Ban;
        delete []Name;
    }
};
void main()
{
     Person p1("男",18,"张三");
     p1.show();
     Student s1("女",19,"李四","511721015","计算机4班");
     s1.show();
}

--------------------Configuration: 作业 - Win32 Debug--------------------
Compiling...
111222333.cpp
C:\作业\111222333.cpp(40) : error C2144: syntax error : missing ')' before type 'char'
C:\作业\111222333.cpp(40) : error C2612: trailing 'typedef' illegal in base/member initializer list
C:\作业\111222333.cpp(40) : error C2512: 'Person' : no appropriate default constructor available
C:\作业\111222333.cpp(40) : error C2082: redefinition of formal parameter 'pX'
C:\作业\111222333.cpp(40) : warning C4518: 'int ' : storage-class or type specifier(s) unexpected here; ignored
C:\作业\111222333.cpp(40) : error C2082: redefinition of formal parameter 'O'
C:\作业\111222333.cpp(40) : warning C4228: nonstandard extension used : qualifiers after comma in declarator list are ignored
C:\作业\111222333.cpp(40) : warning C4518: 'char ' : storage-class or type specifier(s) unexpected here; ignored
C:\作业\111222333.cpp(40) : error C2059: syntax error : ')'
C:\作业\111222333.cpp(41) : error C2082: redefinition of formal parameter 'pName'
C:\作业\111222333.cpp(41) : warning C4228: nonstandard extension used : qualifiers after comma in declarator list are ignored
C:\作业\111222333.cpp(41) : error C2143: syntax error : missing ';' before '{'
C:\作业\111222333.cpp(60) : error C2248: 'Name' : cannot access private member declared in class 'Person'
        C:\作业\111222333.cpp(7) : see declaration of 'Name'
C:\作业\111222333.cpp(70) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.

111222333.obj - 1 error(s), 0 warning(s)

加载中
返回顶部
顶部