C ++:不完全类型 [英] C++: incomplete type
本文介绍了C ++:不完全类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码:
template<class T>
class RandomTreeNode {
public:
typedef typename RandomTreeFunction<T>::function_ptr function_ptr;
RandomTreeNode(): left(NULL), right(NULL), threshold(0.0), is_a_leaf(false), data(NULL), function(0){
}
void set_function(function_ptr function){this->function = function;}
function_ptr get_function(){ return this->function;}
void set_threshold(double threshold){this->threshold = threshold;}
double get_threshold(){return threshold;}
void create_left_child(){this->left = RandomTreeNode<T>();}
//returning references so that they can be altered in a recursive tree build algo without excessive copying
RandomTreeNode<T>& get_left_child(){return left;}
void create_right_child(){this->right = RandomTreeNode<T>();}
RandomTreeNode<T>& get_right_child(){return this->right;}
bool is_leaf(){return this->is_a_leaf;}
void mark_as_leaf(){this->is_a_leaf = true;}
const std::vector<T> get_data(){
return data;
}
void set_data(std::vector<T>& data){
this->data = data;
}
private:
RandomTreeNode<T> left;
RandomTreeNode<T> right;
double threshold;
function_ptr function;
std::vector<T> data;
bool is_a_leaf;
};
当编译时,我得到以下错误:RandomTreeNode< T& :: left'有不完整的类型
。任何想法为什么?
推荐答案
因为它是你当前定义的类型。对于类型具有相同类型的成员(对于初学者,它将具有无限大小)没有意义。我想你想要的是具有指向 RandomTreeNode< T>
的指针,而不是直接实例。
Because it's the type you're currently defining. It doesn't make sense for a type to have a member of the same type (for starters, it would have an infinite size). I think what you want is to have pointers to RandomTreeNode<T>
's, not direct instances.
这篇关于C ++:不完全类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文