#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;
}
#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;
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。