overload operator<< as non-friend #MIAX

Q: without the “friend” keyword, how do you support “dump” output like q(cout<<myDog<<endl), where

Dog myDog; // has private fields

Note you can modify Dog class implementation.

%%A: add const pointers to private fields, so the non-friend q(operator<<) can print them.
%%A: change Dog from a class to a struct.
A: c++ reflection is harder than java. Probably overkill here.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s