剛開始學習C++的課程,我找不出這個代碼有什麼問題!我正在製作一個嵌套在其中的幫助類的堆類,它稱爲節點,充當鏈接列表。我得到的錯誤是第12行是:錯誤:請求會員...在非...非類班型
Stack.cpp: In destructor ‘Stack::~Stack()’: Stack.cpp:12:24: error: request for member ‘getNext’ in ‘((Stack*)this)->Stack::node’, which is of non-class type ‘Stack::Node*’
這裏是我的代碼:
#include "Stack.h"
Stack:: Stack()
{
height = 0;
node = 0;
}
Stack:: ~Stack()
{
while(node != 0){
Node *next = *node.getNext();
delete node;
node = next;
}
node = 0;
}
,這裏是我的頭文件:
using namespace std;
class Stack
{
private:
int height;
class Node{
private:
int data;
Node* next;
public:
void setData(int x){
data = x;
}
void setNext(Node* x){
next = x;
}
int getData(){
return data;
}
Node* getNext(){
return next;
}
};
Node* node;
public:
Stack();
~Stack();
void push(int x);
int pop();
int peek();
int getHeight();
bool isEmpty();
};
我希望我可以標記問題,因爲這網頁的副本:http://en.cppreference.com/w/cpp/language/operator_precedence – chris
DERP那熱鬧 – CCguy