I'm learning C++ and in a school assignment I must use a diamond structure even if it is not totally correct.
class Book
{
public:
virtual int getPurchasePrice() const;
protected:
int m_purchasePrice;
};
class AdultBook: virtual public Book{} ;
class ChildrenBook: virtual public Book{} ;
class ComicBook: public AdultBook, public ChildrenBook {} ;
(I removed every methods and constructors to simplify)
Now, if I want to create a ComicBook and to know its purchasePrice, how can I do ? If I do getPurchasePrice() on a ComicBook I get the following error:
error: request for member 'getPurchasePrice' is ambiguous
I thought that putting virtual for ChildrenBook and AdultBook would solve the ambiguity ?