zoukankan      html  css  js  c++  java
  • 动态生成Person类的对象 代码参考

     1 #include <iostream>
     2 #include <string>
     3 
     4 using namespace std;
     5 
     6 class Person
     7 {
     8     private:
     9         string name;
    10         int age;
    11         char sex;
    12     public:
    13         Person(){name="XXX";age=0;sex='m';}
    14         void Register(string,int,char);
    15         void Showme();
    16         ~Person();
    17 };
    18 
    19 void Person::Register(string name, int age, char sex)
    20 {
    21     this->name=name;
    22     this->age=age;
    23     this->sex=sex;
    24     return;
    25 }
    26 
    27 void Person::Showme()
    28 {
    29     cout<<name<<' '<<age<<' '<<sex<<endl;
    30     return;
    31 }
    32 
    33 Person::~Person()
    34 {
    35     cout<<"Now destroying the instance of Person"<<endl;
    36 }
    37 
    38 int main()
    39 {
    40     string name;
    41     int age;
    42     char sex;
    43     cin>>name>>age>>sex;
    44     Person *p1,*p2;
    45     p1=new Person();
    46     p2=new Person();
    47     cout<<"person1:";
    48     p1->Showme();
    49     cout<<"person2:";
    50     p2->Showme();
    51     p1->Register(name,age,sex);
    52     p2->Register(name,age,sex);
    53     cout<<"person1:";
    54     p1->Showme();
    55     cout<<"person2:";
    56     p2->Showme();
    57     delete p1;
    58     delete p2;
    59     return 0;
    60 }
  • 相关阅读:
    期权标的概率密度函数
    Girsanov Theorem
    拉马努金恒等式
    波动率的三类模型
    stack(栈) and heap(堆)
    covar of lognormal variables
    BS 相关的一些近似公式
    布朗运动的一些特殊性质
    排序算法
    Mac node.js
  • 原文地址:https://www.cnblogs.com/Conan-jine/p/12590227.html
Copyright © 2011-2022 走看看