#include<iostream>
using namespace std;
class citizen{
char* name;
char* nationality;
public:
citizen(){
name="Usman";
nationality="pakistani";
}
citizen(char * aName, char * aNationality)
{
name = new char[strlen(aName, aNationality)+1];
strcpy(name,aName);
strcpy(nationality,aNationality);
}
citizen(const citizen &obj){
name = obj.name;
nationality =obj.nationality;
}
void showName(){
cout<<name<<endl;
}
~citizen()
{
delete[]name;
}
};
int main()
{
citizen citizenA;
citizen citizenA("irshad","Pakistani");
citizen citizenB = citizenA;
citizenA.showName();
citizenB.showName();
system("pause");
return 0;
}
fk5122003 0 Newbie Poster
Banfa 597 Posting Pro Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.