inheritance - protected function call c++ -
class base() { protected: void foo(); } class derived : public base { void bar(); } void derived::bar(){ foo(); //this causes error. } i know i'm missing obvious i've been going round in circles hour. how call protected function in derived class?
the error appears in comments linker error, have checked that:
- you have provided definition of protected function e.g.
class base { protected: void foo() { std::cout - the file containing definition has been compiled (added makefile / cmakefile / project file)
- it linked final executable
- see unresolved external symbol in object files , what undefined reference/unresolved external symbol error , how fix it?
it's hard tell more without more info.
also, code contains invalid syntax, causes error(s):
classlower case- no brackets after class name
;after class definition
the following code works (until gets linker) on g++ version 4.9.0:
class base { protected: void foo(); }; class derived : public base { void bar(); }; void derived::bar(){ foo(); }
Comments
Post a Comment