Home > Article > Backend Development > Can You Explicitly Specify Template Parameters in C Constructors?
In C , a class constructor can be defined as a template function. Typically, the compiler determines the template parameters used by examining the arguments passed to the constructor when it is called. However, is there a way to explicitly specify the template parameters instead?
Consider the following class:
struct A { template<typename T> A() {} };
Unfortunately, C 03 does not provide a way to explicitly specify the template parameters of a constructor. The standard states:
[Note: because the explicit template argument list follows the function template name, and
because conversion member function templates and constructor member function templates are called without using a function name, there is no way to provide an explicit template argument list for these function templates.] (§14.5.2/5)
The above is the detailed content of Can You Explicitly Specify Template Parameters in C Constructors?. For more information, please follow other related articles on the PHP Chinese website!