Field 'data' has incomplete type.

I am trying to overload two operators in my class namely the reference operator and the pointer operator. Here is how I overload the two operators:
1
2
3
4
5
6
7
8
9
  reference operator*() const
    {
    return static_cast<IdNode*>(node)-> data;
    }
    
    pointer operator->() const
    {
    return &static_cast<IdNode*>(node)-> data;
    }

However error messages came up saying than in the reference operator function and pointer operation function 'data' is not a member of the class IdNode.

I declared 'data' in my class Idnode as IdNode data in order to solve the earlier error message. On the other hand, a new error message came out saying field 'data' has incomplete type. Since 'data' is still not part of the class IdNode, the problem with the two operation function still stands.

Here is my class IdNode;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class IdNode {
public:
    IdNode(char *s = "", double e = 0) {
        id = strdup(s);
        value = e;
    }
    bool operator== (const IdNode& node) const {
        return strcmp(id,node.id) == 0;
    }
    IdNode *prev;
    IdNode *next;
    IdNode data;

  
private:   
    char *id;
    double value;
    friend class Statement;
    friend ostream& operator<< (ostream& out, const IdNode& r) {
        out << r.id << " = " << r.value << endl;
        return out;
    }
};


PLS HELP...
1
2
3
class A{
  A a;
}
Its size will be infinity.
Last edited on
I don't think you need to put an IdNode inside your class because your class IS the IdNode. Why are you trying to overload the operators? How are you expecting to use them?
Topic archived. No new replies allowed.