I have a class entry
and an ostream& operator <<
overwritten for it. I also have an auxiliary class cursor
and a type conversion operator entry()
.
Then, in my main()
function I have the following expression:
cout << data[4];
where data[4]
is a cursor
, but compilation fails with
error: invalid operands to binary expression
What I want is for a compiler to convert data[4]
to entry
and to use its <<
operator.
Is there any way to call this ostream operator in an aforementioned way without having to add special methods to entry
?
Here are some pieces of code:
class entry
{
friend class cursor;
/*here comes some data*/
public:
friend ostream& operator << (ostream& out, const entry& a);
};
class cursor
{
database* data_;
size_t ind_;
friend class entry;
friend class database;
public:
cursor (database* a, size_t ind);
cursor (const cursor& a);
void operator= (const entry x);
void operator= (const cursor a);
operator entry(); //type conversion
};
and here is what I use in main():
cout << data[4];