Page 1 of 1

creating a copy constructor

Posted: Mon May 24, 2010 11:49 pm
by darknkreepy3#

Code: Select all

#include <iostream>
using namespace std;
//-----
class Person
     {
     private:
          int age;
     public:
          Person(){}
          
          ~Person(){}
          
          Person(int _age)
               {
               age=_age;
               }
          
          Person(Person& tmp)
               {
               age=tmp.age;
               cout << "copy constructor" << endl;
               }
          
          void Info()
               {
               cout << "My age is " << age << endl;
               }
     };
//-----
int main()
     {
     Person Kris(36);
     Person Genny(Kris);
     Genny.Info();
     system("PAUSE");
     return EXIT_SUCCESS;
     }