Me too I have a problem with deep copy
help me..
this is my code i am using visual studio 2008
#include<iostream>
#include<string>
using namespace std;
class Street
{
private:
int stretNumber;
string name;
int numberHouses ;
int *ListHouses ;
public :
Street();
Street(int, string, int);
//Street(const Street & otherStreet);
Street(const Street & Street1);
void destroyHouses();
void inputRoomsInHouses();
void displayHouses();
void print();
~Street();
};
Street::Street()
{
int stretNumber=0;
string name= " ";
int numberHouses = 0 ;
int *ListHouses= NULL;
}
Street::Street(int n, string nam,int nberH)
{
stretNumber=n;
name= nam;
numberHouses = nberH ;
ListHouses= new int [numberHouses];
}
/*Street::Street(const Street & otherStreet)
{
stretNumber=otherStreet.stretNumber;
name= otherStreet.name ;
numberHouses = otherStreet.numberHouses ;
ListHouses=otherStreet.ListHouses;
}*/
void Street::destroyHouses()
{
delete[] ListHouses;
//ListHouses=NULL;
}
Street::~Street()
{
destroyHouses();
}
void Street::inputRoomsInHouses()
{
cout<<"Enter number of rooms in each eleemnt of the ListHouses: ";
for(int i=0;i<numberHouses;i++)
cin>>ListHouses[i];
}
void Street::displayHouses()
{
cout<<"Number of rooms in each eleemnt of Houses: ";
for(int i=0;i<numberHouses;i++)
cout<<ListHouses[i]<<" ";
cout<<endl;
}
void Street::print()
{
cout<<"The stret Number is: "<<stretNumber<<endl;
cout<<"The stret name is: "<<name<<endl;
cout<<"The stret number Houses is: "<<numberHouses<<endl;
displayHouses();
}
Street::Street(const Street & Street1)
{
stretNumber=Street1.stretNumber;
name= Street1.name ;
numberHouses = Street1.numberHouses ;
ListHouses=new int[Street1.numberHouses];
for(int i=0;i<Street1.numberHouses;i++)
ListHouses[i]=Street1.ListHouses[i];
}
int main()
{
int streetNnumber;
int nbeHouses;
string aName;
cout<<"Entr street Nnumber: ";
cin>>streetNnumber;
cout<<"Entr street Name: ";
cin>>aName;
cout<<"Enter number of Houses: ";
cin>>nbeHouses;
Street myStreet( streetNnumber, aName , nbeHouses );
myStreet.inputRoomsInHouses();
myStreet.print();
Street Street1(myStreet);
cout<<"Street1 is: "<<endl;
Street1.print();
Street1.destroyHouses();
cout<<"After destroy Street1: "<<endl;
Street1.print();
system("Pause");
return 0;
}