Returning self as a property Costum Class

is this possible.
(Pseudo-code)

class myclass
{
int a;
int b;
}

...

myclass a;
a.a = 13;
a.b = 21;


printf("%d",a);

(I wanted it to print "13", it means that self value is equal to 'a' property!)
Is this possible?? Thank you in advance!!
Not with printf(). With C++ and iostreams you can do this however.
How?

cout << a;

will this print, a.a ?!

if you properly overload the << operator, yes:

1
2
3
4
5
std::ostream& operator << (std::ostream& o,const myclass& a)
{
  o << a.a;
  return o;
}
If you want to use it often in more than just cout and printf you might want to write a myclass::getSelf() function that returns 'a' (the member variable)
Topic archived. No new replies allowed.