creating a copy constructor

Learning a programming language is hard enough without having to wrangle your computer into compiling and executing your code. From beginners to experts, the tips here will make life in C++ easier.
Post Reply
darknkreepy3#
Site Admin
Posts: 253
Joined: Tue Oct 27, 2009 9:33 pm

creating a copy constructor

Post 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;
     }
Post Reply