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;
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;
c ++ c ++ 11 templates c ++ 14
Elaine
source share