Пример #1
0
//one female rabbit can create another rabbit from father
//better to have reference because it must be initialize
//pointer to created object to avoid shallow copy
Bunny* Bunny::CreateNew(const Bunny& Father){
	//use new to allocate object in heap
	Bunny *tmp = new Bunny;
	tmp->m_pMother = this;
	if(&Father!=nullptr)
		tmp->m_pFather = const_cast<Bunny*>(&Father);
	//not uni- one rabbit can has many children
	//but every one has a mother and father
	tmp->setFeatures();
	m_vDescendants.push_back(tmp);
	return tmp;
}
Пример #2
0
Bunny* Bunny::Init(){
	Bunny *tmp = new Bunny;
	tmp->setFeatures();
	return tmp;
}