本文整理汇总了C++中Being::getBehavior方法的典型用法代码示例。如果您正苦于以下问题:C++ Being::getBehavior方法的具体用法?C++ Being::getBehavior怎么用?C++ Being::getBehavior使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Being
的用法示例。
在下文中一共展示了Being::getBehavior方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: logic_error
/**
* Generate a being from a couple
*/
unique_ptr<Being> BeingFactory::generateBeing(Being & firstParent, Being & secondParent)
{
if (dynamic_cast<Gender &>(*(firstParent.getBehavior("gender"))).get() == dynamic_cast<Gender &>(*(secondParent.getBehavior("gender"))).get()) {
throw logic_error("Parents share the same gender");
}
map<string, vector<string> > mixedChromosomes = map<string, vector<string> >();
for (
map<string, vector<string> >::iterator chromosomeTypeIterator = my_chromosomes.begin();
chromosomeTypeIterator != my_chromosomes.end();
++chromosomeTypeIterator
) {
mixedChromosomes[chromosomeTypeIterator->first].push_back(
((firstParent.getChromosomes())[chromosomeTypeIterator->first])[rand() % 2]
);
mixedChromosomes[chromosomeTypeIterator->first].push_back(
((secondParent.getChromosomes())[chromosomeTypeIterator->first])[rand() % 2]
);
}
unique_ptr<Being> child = move(generateBeing(mixedChromosomes));
child->addParent(firstParent);
child->addParent(secondParent);
firstParent.addChild(*child);
secondParent.addChild(*child);
return child;
}