Home  >  Article  >  Backend Development  >  Can You Explicitly Specify Template Parameters in C Constructors?

Can You Explicitly Specify Template Parameters in C Constructors?

Linda Hamilton
Linda HamiltonOriginal
2024-11-13 03:03:02934browse

Can You Explicitly Specify Template Parameters in C   Constructors?

Explicit Specification of Constructor Template Parameters

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?

Template Constructor Example

Consider the following class:

struct A {
   template<typename T>
   A() {}
};

Explicit Parameter Specification

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn