ヘッダー ファイルのコード、stack.h は次のとおりです。
#include <iostream>
using namespace std;
//template <class T> struct stackNode;
//template <class T>
struct stackNode {
int item;
stackNode *Next;
stackNode *Prev;
//stackNode *Temp;
};
class stackClass {
public:
stackClass();
stackClass(const stackClass &right);
~stackClass();
stackClass &operator=(const stackClass &right);
int counter;
int StackIsEmpty(void);
//stackNode *origptr;
void push( int item, bool &success);
int pop(void);
int GetStackTop(void);
protected:
stackNode *GetStackTopPtr(void);
private:
stackNode *Top;
stackNode *Current;
//stackNode *origptr;
//stackNode<T> *Next;
};
実装ファイル、stack.cpp は次のとおりです。
#include "stack.h"
//constructor
stackClass::stackClass(){
Top = NULL;
int counter = 0;
}
//copy constructor
stackClass::stackClass(const stackClass &right){
if (right.Top == NULL){
Top = NULL;
counter = 0;
}
else {
stackNode * origptr = right.GetStackTopPtr;
stackNode * currptr;
Top = new stackNode;
currptr = Top;
while(origptr->Next != NULL){
currptr->item = origptr->item;
origptr = origptr->Next;
currptr->Next = new stackNode;
currptr->Next->item = origptr->item;
currptr = currptr-> Next;
}
currptr->Next = NULL;
}
}
//Destructor
stackClass::~stackClass(){
while (Top != NULL){
pop();
}
}
//push
void stackClass::push(int item, bool &success){
success = false;
if (Top == NULL){
Top = new stackNode;
Top -> item = item;
Top -> Next = NULL;
Top -> Prev = NULL;
Current = Top;
counter++;
success = true;
}
else {
stackNode * Temp = new stackNode;
Current -> Next = Temp;
Temp -> Prev = Current;
Temp -> Next = NULL;
Current = Temp;
Current -> item = item;
counter++;
success = true;
}
}
int stackClass::pop(void){
if (Top == NULL){
cout<<"Stack is empty"<<endl;
}
else if (counter == 1){
Top = NULL;
delete Current;
counter--;
}
else if(counter > 1){
Current -> Prev -> Next = NULL;
Current = Current -> Prev;
stackNode * Temp = Current -> Next;
delete Temp;
counter--;
}
}
int stackClass::StackIsEmpty(void){
if (counter == 0)
return 1;
else
return 0;
}
int stackClass::GetStackTop(void){
int item = Top->item ;
return item;
}
stackNode *stackClass::GetStackTopPtr(void){
return Top;
}
そしてここに問題があります、
stack.cpp: コピー コンストラクター 'stackClass::stackClass(const stackClass&)':
stack.cpp:19:31: エラー: 'stackClass::GetStackTopPtr' を型 'stackNode* (stackClass::)()' から変換できませんタイプ 'stackNode*'</p>
コンパイラが不平を言う理由がわかりません。問題の行のstack.cppの19行目で、左側のに適切に割り当てられる型right.GetStackTopPrt
が返されるようです。stackNode *
stackNode*
問題が何であるかを知っている場合は助けてください。ありがとう!