Hi, it's probably something small, but I can't seem to find it. So I have a friend set up in my declarations.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
private:
struct Node
{
int Element; // User data item
Node * Next; // Link to the node's successor
};
unsigned Count; // Number of user data items in the set
Node * Head; // Link to the head of the chain
public:
friend ostream& operator<<( ostream&, const Set& );
proj08.set.cpp: In function 'std::ostream& operator<<(std::ostream&, const Set&)':
proj08.set.cpp:162: error: 'Node' was not declared in this scope
proj08.set.cpp:162: error: 'Temp' was not declared in this scope
I dont know why it's not declared. Shouldn't it be because of the friend statement? Sorry, I haven't done this much.
From what I read about C++, I learned that defining structures inside classes, or classes inside classes isn't within the C++ standard. Please don't do that!!! Define your struct outside your class, and create an object to that in your class. And this whole problem will be solved.
Hmm, I'm not exactly sure what you mean. I can't change the library file. I have to write the class using the friend operator inside the class if that what you're talking about.
class MyClass
{
class MySubClass //totally illegal
{
};
};
This is what you're doing... and it's not within the C++ standard. I read that some compilers could accept it, but it still makes problems at some level.
Take your subclass (or struct for this purpose) outside your class, and have an object of your subclass in your class. This should work fine.
Source of info: Professional C++, by Solter and Kleper