简体   繁体   English

你如何写这个模板的定义?

[英]How do you write definition of this template?

How do you write the definition of this template?这个模板的定义怎么写?

fun<10>();// output is 10  
fun<20>();// output is 20
template <int32_t N>
void fun() {
    std::cout << N << std::endl;
}

It is called a non-type template parameter.它被称为非类型模板参数。

And the parameter here ( int32_t N for instance in the above example) can be one of the following types (until C++20):此处的参数(例如上例中的int32_t N )可以是以下类型之一(直到 C++20):

  1. std::nullptr_t (since C++11); std::nullptr_t (C++11 起);

  2. an integral type;一个整体类型;

  3. a pointer type (to object or to function);指针类型(指向对象或函数);

  4. a pointer to member type (to member object or to member function);指向成员类型的指针(指向成员对象或成员函数);

  5. an enumeration type.枚举类型。

Reference: template parameter参考: 模板参数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM