Home > Backend Development > C++ > body text

Can You Explicitly Specify Template Parameters in C Constructors?

Linda Hamilton
Release: 2024-11-13 03:03:02
Original
901 people have browsed it

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() {}
};
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template