c++ - Adding a virtual function to a sub-subclass without it being in the subclass? -


edit: dyp pointed in comments below, typo in function definition in c3(soccerworld).

  • i have class, c1, has virtual function, f.
  • another class, c2 inherits c1, , c3 inherits c2.
  • c2 doesn't have virtual function f, want add c3 changes.
  • the virtual function f in c1 isn't pure, , defined in c1.cpp. still need f in c1, well.

when adding f c3, , not c2, unresolved external symbol error. if add f c2 virtual function well, 2 errors: 1 same before, , in c1.obj says f exists in c3.

this c1, c2, c3 like:

class c1 {    virtual void f() { ... } };  class c2 : public c1 {    //no virtual f };  class c3 : public c2 {    virtual void f() { /*do something*/ } }; 

real f function:

abstractkart *world::createkart(const std::string &kart_ident, int index, int local_player_id, int global_player_id, racemanager::karttype kart_type) { ... } 

this in class world. class worldwithrank inherits world, , doesn't have createkart function. class soccerworld inherits worldwithrank , want have createkart place karts differently if it's soccerworld.

createkart protected in world.

error:

world.obj : error lnk2005: "protected: virtual class abstractkart * __thiscall world::createkart(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int,int,int,enum racemanager::karttype)" (?createkart@world@@maepavabstractkart@@abv?$basic_string@du?$char_traits@d@std@@v?$allocator@d@2@@std@@hhhw4karttype@racemanager@@@z) defined in soccer_world.obj  soccer_world.obj : error lnk2001: unresolved external symbol "protected: virtual class abstractkart * __thiscall soccerworld::createkart(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int,int,int,enum racemanager::karttype)" (?createkart@soccerworld@@maepavabstractkart@@abv?$basic_string@du?$char_traits@d@std@@v?$allocator@d@2@@std@@hhhw4karttype@racemanager@@@z) 

reposted comment op:

guessing errors, think rather have typo. looks in soccer_world.cpp, defined function abstractkart *world::createkart(...) instead of abstractkart *soccerworld::createkart(...).

this creates second definition of abstractkart *world::createkart(...), explains first error:

world.obj : error lnk2005: "protected: virtual class abstractkart * __thiscall world::createkart([...])" [...] already defined in soccer_world.obj

the second error occurs if try call not-defined abstractkart *soccerworld::createkart(...):

soccer_world.obj : error lnk2001: unresolved external symbol "protected: virtual class abstractkart * __thiscall soccerworld::createkart([...])" [...]


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -