c++ - Does instantiating a template instantiate its static data members? -
c++ - Does instantiating a template instantiate its static data members? -
with regard explicit instantiation (iirc used when template declare in header , defined in cpp file because otherwise linker not able find when using somewhere else), if template has static fellow member variable, explicit instantiation instantiate , create static fellow member variable?
if explicitly instantiate class template, non-template members instantiated, including static
info members long have definition. example:
template <typename t> struct foo { static int static_data; void non_template_member() {} template <typename s> void template_member(s) {} }; template <typename t> int foo<t>::static_data = 0; template struct foo<int>; template struct foo<double>;
the explicit instantiations @ bottom create definitions static_data
, non_template_member()
types int
, double
. there won't definition template_member(s)
still open set.
if not provide [templated] definition static_data
, won't instantiate corresponding definition.
the relevant section of standard 14.7.2 [temp.explicit] paragraph 8:
an explicit instantiation names class template specialization explicit instantiation of same kind (declaration or definition) of each of members (not including members inherited base of operations classes , members templates) has not been explicitly specialized in translation unit containing explicit instantiation, except described below.
without fellow member definition static
fellow member declared , explicit instantiation simply see declaration beingness instantiated. definition explicit instantiation becomes definition.
c++ templates
Comments
Post a Comment