How could I call a base class virtual function from the derived class ? (C++)

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 7K views
walnutTree
Messages
5
Reaction score
0
Dear All,
I have got a subclass (Panda), which inherits a Print function from the base class (Bear).
I'd like to be able to call the base class's function from the subclass.
But my complier gives me the following error message:

In member function `virtual void Panda::print(char)':
expected primary-expression before "char"


I use DEV-CPP.
Heres is my code causing the problem:

Code:
class Bear{
      public:
             virtual void print(char x)
             {
                 std::cout<<"bear"<<std::endl; 
             }
      };
class Panda : public Bear{
    public:
             void print(char x)
             {
                Bear::print(char x);
                std::cout<<"panda"<<std::endl;  
             }  
      };

Could you tell me what's the wrong?
Any ideas would be appreciated!
 
Physics news on Phys.org
Look very closely at this line:
walnutTree said:
Code:
                Bear::print(char x);
It's a function call, so more like this:
Code:
                Bear::print(x);
If you're like me, you've slapped yourself in the forehead and groaned by now. :wink:
 
thanks for clearing things up, it was a rookie mistake...
and the slapping took place as well:)