C++ (Cpp) iLiving Example

Introduction

The c++ (cpp) iliving example is extracted from the most popular open source projects, you can refer to the following example for usage.

Programming language: C++ (Cpp)

Class/type: iLiving

Example#1
File: creature.cppProject: kizzie/cboe

bool cCreature::is_friendly(const iLiving& other) const {
	if(is_friendly() != other.is_friendly())
		return false;
	if(const cCreature* monst = dynamic_cast<const cCreature*>(&other)) {
		if(!is_friendly()) return attitude == monst->attitude;
	}
	// If we get this far, both monsters are friendly to the player.
	// (Or, maybe the other is a player rather than a monster.)
	return true;
}

Example#2
File: party.cppProject: calref/cboe

bool cParty::is_friendly(const iLiving& other) const {
	return other.is_friendly();
}