Does the following default argument for the template instantiates a template with type EmptyClass
?
class EmptyClass{};
template <typename TYPE=EmptyClass>
class Sample
{
public:
static void test()
{
TYPE::Serialize();
}
};
Does the following default argument for the template instantiates a template with type EmptyClass
?
class EmptyClass{};
template <typename TYPE=EmptyClass>
class Sample
{
public:
static void test()
{
TYPE::Serialize();
}
};
No. Template are instantiated when used, and are instantiated on a per-function base.
Default parameter values are just the types to use when the parameter is not specified. But does not themselves imply usage.
When you call Sample<>::test()
then Sample<Emptyclass>::test()
is instantiated and the EmptyClass::serialize()
call attempted, resulting in a compile-time error (Since Emptyclass
is declared as not having such function)
Try to make up more function, containing different compile-time errors referring to different parameter, and you'll see how, until the function is not used, no error is produced.
No, in that code any instance of EmptyClass is created. Serialize is a static function. And EmptyClass's constructor is never called (in code showed)