C ++:不完全类型

编程入门 行业动态 更新时间:2024-10-23 22:27:03
本文介绍了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 ++:不完全类型

本文发布于:2023-11-27 08:56:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637384.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不完全   类型

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!