开发者

operator<< overload in C++ for a class in class

开发者 https://www.devze.com 2023-04-05 11:53 出处:网络
i have the following classes: class mypipe { class node { public: char ch; node* next; node(){...} node(char c){..}

i have the following classes:

class mypipe {
    class node {
        public:
            char ch;
            node* next;

            node(){...}
            node(char c){..}
    } ;      
public:
    unsigned int size;
    node* head;

and i need to overload the operator<<, to print the mypipe as it is now.

then, i'm trying to write the following:

friend ostream& operator<< (ostream& stream, mypipe p)  {
     node* curr = p.head -> next;
...

immediately after the variables definition.

the problem is that i开发者_JAVA百科 get an error "identifier node is undefined".

i've tried to declare the operator and implement it outside of the class, that didn't help.

does anyone have any ideas about it?

thanks in advance for anyone who can help :)


node is an inner class, which means you have to qualify its type:

mypipe::node* curr = p.head -> next;
0

精彩评论

暂无评论...
验证码 换一张
取 消