我有一個樹狀結構類命名在我的C++程序SuperTree
,我希望它有一個返回一個實例方法struct
或pair
其中一個屬性是一個指向SuperTree
對象。結構返回函數在C++類
我SuperTree
類insert
函數返回一個Res
結構,其中包含到另一個SuperTree
對象和一個布爾值的參考。但是,如果我嘗試編譯代碼時,我得到了以下錯誤消息:
supertree.cpp:24: error: ISO C++ forbids declaration of ‘Res’ with no type
我也不能我SuperTree
類之前定義Res
結構,因爲它會不會或者編譯。也許這是C++泛型類型的一些情況(我不知道如何使用)。
所以這是我的嘗試:
#include <cstdio>
#include <utility>
using namespace std;
class AVL {
public:
int key;
int bf;
AVL* leftChild;
AVL* rightChild;
AVL()
{
}
~AVL() {};
AVL rotateLeft();
AVL rotateRight();
Res* insert(int value);
int remove();
int size();
};
// typedef pair<AVL, bool> result;
typedef struct result {
struct AVL *avl;
bool changed;
} Res;
注意,pair
定義已被註釋掉,但我你們能回答對他們來說我很高興!
原來是這樣,我怎麼能有SuperTree
類和Res
結構,在我SuperTree
類Res
指針返回函數兩者兼而有之?
任何幫助,歡迎。謝謝!