Why defining a static error pointer for nested structural reports when using a template alias

The following code is a class template. Outside the class, I define static elements. However, two methods are used to determine the static member of PrimeBlock *, method - 1 uses the template alias, and it reports a re-allocation error; method - 2 may work correctly. I wonder why method - 1 cannot work.

template <typename tree_type> class Tree { struct PrimeBlock { vector<tree_type*> vec; }; static tree_type* ROOT; static PrimeBlock* primeBlock; }; template <typename tree_type> tree_type* ROOT = nullptr; // method - 1 template alias for definition - error template <typename tree_type> using PrimeBlock = typename Tree<tree_type>::PrimeBlock; template <typename tree_type> PrimeBlock<tree_type>* Tree<tree_type>::primeBlock = nullptr; // this cannot work due to redeclaration error // method - 2 - it works //template <typename tree_type> //typename Tree<tree_type>::PrimeBlock* Tree<tree_type>::primeBlock = nullptr; // however, this could work, why? 

Error message generated by method - 1

 error: conflicting declaration 'PrimeBlock<RtreeVariant>* Tree<RtreeVariant>::primeBlock' PrimeBlock<RtreeVariant>* Tree<RtreeVariant>::primeBlock = nullptr; note: previous declaration as 'Tree<RtreeVariant>::PrimeBlock* Tree<RtreeVariant>::primeBlock' static PrimeBlock* primeBlock; error: declaration of 'Tree<RtreeVariant>::PrimeBlock* Tree<RtreeVariant>::primeBlock' outside of class is not definition [-fpermissive] PrimeBlock<RtreeVariant>* Tree<RtreeVariant>::primeBlock = nullptr; 
+7
c ++ c ++ 11 templates c ++ 14
source share

No one has answered this question yet.

See similar questions:

41
Why does the alias pattern give a conflicting declaration?

or similar:

24
Why does GCC consider the definition of a static constexpr element to be marked with constexpr?
23
Nested template classes with a pointer to a method not compiled in clang ++
14
Correct initialization of constexpr static array in class template?
nine
Why does constexpr static member (of type type) require a definition?
8
C ++ templates and static members - definition in title
2
Defining a move method for a nested template class outside the declaration
one
Getting / setting static elements of the template structure at run time
0
Static function pointer element in class template
0
C2998 cannot be a template definition error
0
Unable to access type alias from class template definition in a separate file without entering full alias type declaration

All Articles