保健酒包装:简单C ++ 麻烦帮我看一下哪错了
来源:百度文库 编辑:杭州交通信息网 时间:2024/06/04 05:04:30
#include<iostream>
using namespace std;
class Teacher
{
public:
Teacher(char *tName,int tTime);
void show();
char *getName() const{return name;}
int getTime() const{return time;}
protected:
char *name;
int time;
};
Teacher::Teacher(char *tName,int tTime)
{
name=tName;
time=tTime;
}
void Teacher::show()
{
cout<<"name: "<<getName()<<endl
<<"time: "<<getTime()<<endl;
}
class Professor:public Teacher
{
public:
Proessor( char *pName, int pTime):Teacher( pName,pTime){}
};
using namespace std;
class Teacher
{
public:
Teacher(char *tName,int tTime);
void show();
char *getName() const{return name;}
int getTime() const{return time;}
protected:
char *name;
int time;
};
Teacher::Teacher(char *tName,int tTime)
{
name=tName;
time=tTime;
}
void Teacher::show()
{
cout<<"name: "<<getName()<<endl
<<"time: "<<getTime()<<endl;
}
class Professor:public Teacher
{
public:
Proessor( char *pName, int pTime):Teacher( pName,pTime){}
};
Proessor( char *pName, int pTime):Teacher( pName,pTime){}
应该是Professor ,呵呵
类Professor的构造函数名写错了,应该与类名相同
另外,没有主函数,这样链接时会有错
The name field is very vulnerable in some cases.