我有一堂课Tree
:
class Tree {
string aboutTree;
vector<int> veryImportantInfo;
Tree* leftChild;
Tree* rightChild;
...
void veryImportantMethod() {
// change and use aboutTree
// change and use veryImportantInfo
}
};
aboutTree
并且veryImportantInfo
不是恒定的,但对于树的所有节点都是相同的,我不想在所有节点中复制它。我想要这样的东西:
class Tree {
//string aboutTree;
//vector<int> veryImportantInfo;
Tree* leftChild;
Tree* rightChild;
...
void veryImportantMethod() {
// change and use aboutTree
// change and use veryImportantInfo
}
};
class TreeWrapper {
string aboutTree;
vector<int> veryImportantInfo;
Tree root;
...
};
但这是行不通的,因为我无法访问TreeWrapper
.