0

I want to do something like this:

class foo
{
private:
class foo2
{
...
void Print (ostream & out)
....
};
ostream & operator << (ostream &out, const foo & temp);
public:
...
}

I want it so class foo can cout << foo2 objects only in the foo class. But when I try to do this, it gives me problems. Is there a way to do this, or should I just rely on a basic void Print() method?

Mistro116

Edited by happygeek: fixed formatting

2
Contributors
2
Replies
3
Views
10 Years
Discussion Span
Last Post by Mistro116
0

you could make foo1 a base class

class foo1()
{
// blabla
};

class foo : private foo1
{
  // blabla
};

But then we can create foo1 classes outside of foo, which is NOT what I want to happen. I only want foo to use the overloaed << for foo1, and I want this function to be a private member function outside of foo1, where foo1 is nested in the private section of foo. That way, only foo objects can cout << foo1 objects.

Any idea as to how? I tried friend, member function, non-member function. I got argument errors for all of these...

Mistro116

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.