The function whoAmI() is supposed to return:
I am a Man I am a Omnivore But it just returns "I am a Man" twice:
class Animal { public: string className; }; class Omnivore:public Animal { public: Omnivore() { className = "Omnivore"; } }; class Man:public Omnivore { public: Man() { className = "Man"; } void whoAmI() { cout << "I am a " << Omnivore::className << endl; cout << "I am a " << Omnivore::Animal::className << endl; } };
classNamefor a giventhis, regardless of how you refer to it.classNamea (virtual or static) function, then it will work.whoAmI()doesn't return anything - it'svoid.