Re: Tree Hashing / Equivalence
Al wrote:
Chris Uzdavinis wrote:
On Jan 28, 9:13 am, Al <t...@haik.us> wrote:
Let's say I have a node type such as:
class Node {
std::vector<Node> Children;
std::string Value;
int ID;
};
Perhaps this is just sample code for posting, but be careful with this
construct because the vector is being declared with an incomplete type
as its template argument, resulting in undefined behavior. (17.4.3.6)
Thanks for pointing this out. I based my node code on Boost.Spirit's,
which has, in <boost/spirit/tree/common.hpp>:
template <typename T>
struct tree_node
{
//...
typedef std::vector<tree_node<T>, allocator_type> children_t;
//...
children_t children;
//...
};
Well, you've copied something wrong, because there's no
allocator_type that I can see. In my tests, I dropped the
allocator argument (so that the compiler will pick up the
default). The issue is different, because in this case,
you're dealing with a template, where tree_node<T> is a
dependant name. As such, it won't be evaluated until the
template is instantiated. At which point, I get a lot of
errors from g++. Are you sure that children_t isn't:
typedef std::vector< tree_node<T>*, allocator_type > children_t ;
A pointer to an incomplete type is, itself, a complete type.
--
James Kanze (Gabi Software) email: james.kanze@gmail.com
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]