#include
#include
using namespace std;
class Person
{
private:
char *name;
public:
Person(char *n1):name(n1){strcpy(name,n1);}
void PrintName() {cout<<"The name is:";}
};
class Student:public Person
{
private:
long int Number;
public:
Student(char *n2,long int n3):Person(n2) {Number=n3;}
void PrintInfo()
{
cout<<"The number is:";
}
};
int main()
{
Person a("张三");
cout<<a.PrintName<<endl;
Student b("张三",142180217);
cout<<b.PrintInfo<<endl;
return 0;
}
请帮忙看看错误吧。。。
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
7条回答
- threenewbee 2015-05-29 03:41关注
#include<iostream> #include<string> using namespace std; class Person { private: char *name; public: Person(char *n1):name(n1){strcpy(name,n1);} void PrintName() {cout<<"The name is:" << name; } }; class Student:public Person { private: long int Number; public: Student(char *n2,long int n3):Person(n2) {Number=n3;} void PrintInfo() { cout<<"The number is:" << Number; } }; int main() { char ch[] = "张三"; Person a(ch); a.PrintName(); cout << endl; Student b(ch,142180217); b.PrintInfo(); cout << endl; return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报