Try the following
std::ostream & operator <<( std::ostream &outstream, const class Item &item );
class Item
{
public:
std::string name;
Item( const std::string &input ) : name( input )
{
std::cout << *this;
}
};
std::ostream & operator<<( std::ostream &outstream, const Item &item )
{
outstream << item.name;
return outstream;
}
Or if data member name will be defined as private then you can write
class Item
{
private:
std::string name;
public:
Item( const std::string &input ) : name( input )
{
std::cout << *this;
}
friend std::ostream & operator <<( std::ostream &outstream, const Item &item );
};
std::ostream & operator<<( std::ostream &outstream, const Item &item )
{
outstream << item.name;
return outstream;
}
The same way you can overload operator
std::ostream & operator <<( std::ostream &outstream, const class Item *item );
if you need. However in fact there is no need to overload this operator. It is enough to have the operator where reference to an object of thbe class is used as parameter.