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
inheritsc1
, ,c3
inheritsc2
. c2
doesn't have virtual functionf
, want addc3
changes.- the virtual function
f
inc1
isn't pure, , defined inc1.cpp
. still needf
inc1
, 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
Post a Comment