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
Post a Comment