Member functions of class templates are only created when called. If you never call A::A(), then the calling code T::T()should not compile in this code:
template <class T>
struct A {
A() : t(T()) {
}
};
? , ?
, A , , , - T A::A() :
template< typename T >
struct default_a_ traits {
static T default_construct()
{
return T();
}
};
template <class T, class Traits = default_a_traits<T> >
struct A {
A() : t(Traits::default_construct()) {
}
};
, , , T - :
struct my_special_traits_for_b {
static T default_construct()
{
return read_b_from_db();
}
};
typedef A<B, special_traits_for_b> AB;