The below code should obviously not compile (Equivalent to defining a class as C { C myC }
, which would take infinite memory). The question is how does C++ actually do the check?
class Node {
vector<Node> mChildren{ Node }
}
When I try to compile, I get the following error.
trie.cpp:6:35: error: expected primary-expression before ‘}’ token
vector<Node> mChildren { Node };
^
trie.cpp:6:35: error: could not convert ‘{<expression error>}’ from ‘<brace-enclosed initializer list>’ to ‘std::vector<Node>’
Is it because the class Node has yet to be fully declared? How come I can use it as a template argument to vector. A similar issue arises with
class C {
C myC;
};