【发布时间】:2015-06-04 15:47:01
【问题描述】:
我目前正在编写一个树类,想实现一个构造函数来创建具有一定维度和深度的树:
public:
tree(); // empty constructor
tree(int dimension, int depth); // constructing an empty tree
// ...
void newNode(node<T>* const&, T const&);
// ...
private:
unsigned int mNumNodes;
node<T> *mRoot;
template<typename T>
tree<T>::tree(int dimension, int depth):
// member vars
{
// other constructing stuff
this->newNode(0, parent);
}
显然这样的事情是不可能的,但是当我编写了一个很好的工作函数来将新节点添加到具有特定值的特定父节点时,使用它会很好。
但是:此方法需要访问当前对象。
也许有某种解决方案对我有用,既不能指向 obj,也不能使用任何其他类型的访问。
【问题讨论】:
-
为什么不
this->newNode(mRoot, parent);? -
请提供SSCCE。
-
因为树没有被构造成一个指针并且有:
no matching function for call to ‘tree<std::basic_string<char> >::newNode(int, node<std::basic_string<char> >*&)’ -
@NathanOliver 为此我必须粘贴一个 80 行长的节点标题。
-
@hGen - Re 因为树不被构造为指针 - 如果你的意思是
this指针,它肯定是。
标签: c++ object constructor