So basically let's say I have 2 classes now. 1 is called Human and the other one is called House.
What I have done now is made that the house makes and destroys human, so basically in the House .h file I have
Human *humanP;
And in the .cpp files constructor
humanP = new Human;
humanP->something(); // lets me access the methods in the Human class
As far as I know this makes a composition and House creates/destroys the Human object. But I need to add parameters to my Human object like height and age for example.
In the main I want to have something like
int age, height;
cout << "Whats your age? << endl;
cin >> age;
cout << "Whats your height? << endl;
cin >> height;
With this I want to make
Human humanO(age, height);
Which will create Human object with those parameters. But I still want the Human object to be held in House class and then destroyed there. As far as I know I need to make a deep copy of that, so that I can copy the humanO inside the House class and then delete the object in the main file.
I've been looking trough examples but there are quite a lot of different ones, could anyone write what the code would look like to make a deep copy of this Human object that is created in main?
Edit:
Making an edit here instead of replying cause it's easier to write code here.
Okay another stupid question. If I use the simple method with
Human *newPerson = new Human
and do
House house;
house.addHuman(newPerson)
while having the class method
addHuman(Human *other)
{
this->humanP = other;
cout << humanP->getAge() << endl << endl << endl;
}
it works fine and gives me the age.
If I use smart pointers it doesn't work, what should I change? It gives me errors like "no matching function". What arguments should I put into the addHuman()
so that it would take the smart pointer thingy?