|
-
May 7th, 2002, 12:13 PM
#1
overloading ostream for a class
I have many values stored in a class under the protected: heading. In the public section of the function I have a ostream friend ( ostream & operator << (ostream &o, const class c) ). In the ostream friend I tried o << on the values stored in the class ( o << c.value; ). I get the compiler error 'value' : cannot access protected member declarded in class.
First off why doesn't this work, shouldn't the program make a copy of the class in the varible c, I thought when you passed a class by value it called the default constructor and copy constructor to make a copy of your class. Why can't the function who owns the class varible not access the protected memebers?
I'm not going to have to make a public function to return all the values from the protected section, am I? That would seriously suck!
I know there must be an easier way, some one care to enlighten the dim-witted
NOMAD
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|