123456789101112131415161718192021222324
class A { public: void a_function(){}; }; class B : public A { }; class C: public B, public A { C(); }; C::C() { a_function(); // error here }
123
error: reference to 'a_function' is ambiguous error: candidates are: void A::a_function() error: void A::a_function()
1234
class C: virtual public B, virtual public A { C(); };
123456789101112131415161718192021
class GameObject : virtual public sf::Sprite { public: virtual void GameLoop(sf::RenderWindow &w)=0; // ... }; class Player: virtual public sf::Sprite, virtual public GameObject { public: Player(); void GameLoop(sf::RenderWindow &wnd){} // from GameObject // ... }; Player::Player() { Scale(0.1,0.1); // Inherited from sf::Sprite }
12345678910111213141516
std::vector<GameObject*> game_objects; GameObject *player=new Player; game_objects.push_back(player); // ... // call GameLoop function when needed for(int i=0;i<game_objects.size();i++) game_objects[i]->GameLoop(wnd); // Draw objects for(int i=0;i<game_objects.size();i++) wnd.Draw(*game_objects[i]);