c++ - operator<< doesn't find match -
class shape { virtual void out() = 0; }; std::ostream& operator<<(std::ostream& os, shape& a) { return os << a.out(); } i want create abstract base class , able use cout << triangle/square etc. later on, triangle, square being derived classes shape.
it works fine if return os << "test"; i'm guessing it's a.out() not getting called properly, can't seem pinpoint problem.
the out member function returns void, doesn't return object pass std::ostream::operator<<. perhaps want return std::string?
Comments
Post a Comment