I need to overload the << operator as a virtual function. I've only ever done them as friend functions and friend functions can't be virtual functions so I'm running into problems.
In the base class I'm using it as a pure virtual function:
and in the derived class I'm using it like thisCode://header virtual void operator<<(ostream &, const Holding &) = 0;
Code://header virtual void operator<<(ostream &, const Book &);I'm getting these errors from it:Code://.cpp void Book::operator<<(ostream &out, const Book &book){ book.print(out); }
`void Book::operator<<(std::ostream&, const Book&)' must take exactly one argument
and
In member function `virtual void Book::operator<<(std::ostream&, const Book&)':
and
`const Book' as `this' argument of `virtual void Book::print(std::ostream&)' discards qualifiers
and
cannot allocate an object of type `Book'
because the following virtual functions are abstract:
virtual void Holding::operator<<(std::ostream&, const Holding&)
What do you think might be the problem?



LinkBack URL
About LinkBacks



.