简体   繁体   中英

'Undeclared identifier' / 'identifier "x" undefined' / 'class Y has no member "x" ' working with struct-type pointers

I have my class Queue (declared in Queue.h and implemented in Queue.cpp) and the 'Node' struct defined in the Queue.h file, like this:

Queue.h

//...
typedef int TElem;
struct Node{
    TElem data;
    Node *next;
};
class Queue
{
private:
    Node *head;
    Node *tail;
public:
    // ... some other methods
}

Then, in Queue.cpp

//...
Queue::Queue()
{
    head = nullptr;
    tail = nullptr;
}

These last 2 lines of code in my constructor produce 4 errors, two for each line: 'identifier "head" is undefined' / 'identifier "tail" is undefined' and "'head': undeclared identifier" / "'tail': undeclared identifier". Why is this and how can I solve this ? I have read answers to similar questions, yet none answered mine.

I am sorry for this, there was a problem with my files. I did something bad with the files when creating the project. The code ran just fine afterwards.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM