c++ - Static member initialization in a class template -


i'd this:

template <typename t> struct s {     ...     static double something_relevant = 1.5; }; 

but can't since something_relevant not of integral type. doesn't depend on t, existing code depends on being static member of s.

since s template, cannot put definition inside compiled file. how solve problem ?

just define in header:

template <typename t> struct s {     static double something_relevant; };  template <typename t> double s<t>::something_relevant = 1.5; 

since part of template, templates compiler make sure it's defined once.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -