开发者社区> 问答> 正文

c++分配内存空间

a123456678 2016-03-06 11:55:29 870
#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;
}
分享到
取消 提交回答
全部回答(1)
  • a123456678
    2019-07-17 18:54:22
     #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;
    }
    0 0

集结各类场景实战经验,助你开发运维畅行无忧

推荐文章
相似问题