Q:

Derived class does not have access to inherited function?

I'm creating a very simple program that involves inheritance.  I put a function into the "protected" area of the parent class, and now I don't have access from the child class.  Here is my code:
class Product : protected Item 
{

private:

    double Price;

protected:

    double getPrice(){return Price;}

//other code not connected
};

Later on, I derive:
class Toy : protected Item
{

// class Toy code that does not mention getPrice() at all

 };

And after that, I derive another class in which I actually try to use the getPrice() function.
In the new class's header file:
class Game : protected Toy
{

  double printGame(){return getPrice();}
};

This line does not give me an error.  
But in the file game.cpp:
ostream& operator << (ostream& Output, const Game &printedGame)
{
 return Output 

 << "The game price is: "

 //This is the problem line

 << printedGame.printGame()

 << "." ;
 }

The word "printedGame" returns me "Error:  the object has type qualifiers that are not compatible with the member function"
When I tried going directly (which I tried before, as such:)
printedGame.getPrice()

I get that error, and an additional one informing me that the getPrice() function is not accessible.
Any help here?  Thanks!!

A:

Your << operator is called with a const Game & object which means that the function may only call const member functions of Game
Add const to getPrice and printGame:
double getPrice() const {return Price;}
double printGame() const {return getPrice();}

You'll also have to make printGame public.

