C ++ is new here! There is a class Individualthat highlights a lot of memories, so we want to avoid copying. Let motherand fatherbe two Individuals. I would like them to reproduce using a method reproduceto make another one Individualcalled baby.
Intuitively, I would initialize babywith the default constructor, pass it in an argument reproduceand return the link (although, I suppose, there is no need to return the link). Here is the code that does this
class Individual
{
public:
void reproduce (const Individual& father, Individual& baby)
{
}
private:
}
int main()
{
Individual mother(arg1,arg2,arg3);
Individual father(arg1,arg2,arg3);
Individual baby;
mother.reproduce(father,baby);
}
Is this a good practice?
baby reproduce , , baby reproduce, .
class Individual
{
public:
Individual& reproduce (const Individual& father)
{
Individual baby;
return baby
}
private:
}
int main()
{
Individual mother(arg1,arg2,arg3);
Individual father(arg1,arg2,arg3);
auto baby = mother.reproduce(father);
}
, , .