code file is attached ....

[#include<iostream>
using namespace std;
class citizen{
      char* name;
      char* nationality;
      public:
             citizen(){         //default constructor
                       name = "Usman";
                       nationality = "pakistani";
                       }
             citizen(char *aName, char *aNationality)  //parameterized constructur
             {
                          name = new char[strlen(aName, aNationality)+1];
                          strcpy(name, aName);
                          strcpy(nationality, aNationality);
                          }
                          citizen(const citizen &obj){      //copy constructor
                          name = obj.name;
                          nationality = obj.nationality;
                          }
                          void showName(){
                               cout<<name<<endl;
                               cout<<nationality<<endl;
                               }
                          ~citizen()
                          {
                                    delete[]name;
                                    }
                                    };
          int main()
          {
              citizen citizenA;
              citizen citizenA("irshad","pakistani");
              citizen citizenB = citizenA;
              citizenA.showName();
              citizenB.showName();
              system("pause");
              return 0;
          }

// Errors
C:\Dev-Cpp\include\string.h In constructor `citizen::citizen(char*, char*)':
13 C:\Documents and Settings\crystal\Desktop\Untitled2.cpp at this point in file
C:\Documents and Settings\crystal\Desktop\Untitled2.cpp In function `int main()':
32 C:\Documents and Settings\crystal\Desktop\Untitled2.cpp `citizen citizenA' previously declared here
33 C:\Documents and Settings\crystal\Desktop\Untitled2.cpp redeclaration of `citizen citizenA'
C:\Dev-Cpp\include\string.h In constructor `citizen::citizen(char*, char*)':

Edited 6 Years Ago by WaltP: Added CODE Tags

Attachments
#include<iostream>
using namespace std;
class citizen{
      char* name;
      char* nationality;
      public:
             citizen(){         //default constructor
                       name = "Usman";
                       nationality = "pakistani";
                       }
             citizen(char *aName, char *aNationality)  //parameterized constructur
             {
                          name = new char[strlen(aName, aNationality)+1];
                          strcpy(name, aName);
                          strcpy(nationality, aNationality);
                          }
                          citizen(const citizen &obj){      //copy constructor
                          name = obj.name;
                          nationality = obj.nationality;
                          }
                          void showName(){
                               cout<<name<<endl;
                               cout<<nationality<<endl;
                               }
                          ~citizen()
                          {
                                    delete[]name;
                                    }
                                    };
          int main()
          {
              citizen citizenA;
              citizen citizenA("irshad","pakistani");
              citizen citizenB = citizenA;
              citizenA.showName();
              citizenB.showName();
              system("pause");
              return 0;
          }
This article has been dead for over six months. Start a new discussion instead.