Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 理解基于策略的模板的定义 模板< 类型名T, 模板类OwnershipPolicy=RefCounted,#1 类转换策略=不允许转换版本,#2 模板类CheckingPolicy=AssertCheck, 模板类StoragePolicy=DefaultSPStorage > 类智能ptr;_C++_Templates - Fatal编程技术网

C++ 理解基于策略的模板的定义 模板< 类型名T, 模板类OwnershipPolicy=RefCounted,#1 类转换策略=不允许转换版本,#2 模板类CheckingPolicy=AssertCheck, 模板类StoragePolicy=DefaultSPStorage > 类智能ptr;

C++ 理解基于策略的模板的定义 模板< 类型名T, 模板类OwnershipPolicy=RefCounted,#1 类转换策略=不允许转换版本,#2 模板类CheckingPolicy=AssertCheck, 模板类StoragePolicy=DefaultSPStorage > 类智能ptr;,c++,templates,C++,Templates,Q1>第1行的语法是什么 template class OwnershipPolicy=RefCounted, 为什么它不提供如下参数 template <class> class OwnershipPolicy = RefCounted, template class OwnershipPolicy=RefCounted, 第二季度>第1季度和第2季度之间有什么区别 template <class T2> class OwnershipPolicy = RefCo

Q1>第1行的语法是什么

template class OwnershipPolicy=RefCounted,
为什么它不提供如下参数

template <class> class OwnershipPolicy = RefCounted,
template class OwnershipPolicy=RefCounted,
第二季度>第1季度和第2季度之间有什么区别

template <class T2> class OwnershipPolicy = RefCounted,
template class OwnershipPolicy=RefCounted,
类转换策略=不允许转换版本,
为什么其中一行有
模板
,而另一行没有?

模板类所有者政策
是一个模板参数。也就是说,
OwnershipPolicy
应该是一个使用一个(并且只有一个)类型参数的模板。这个论点没有名字,因为它不需要,而且你无论如何也不能用它做任何事情

类转换策略
等同于
类型名转换策略
,即任何普通类型参数

区别在于你如何使用它。对于模板参数,只提供模板的名称,稍后可以使用该名称实例化具体类型。对于
typename
,您需要一个具体的类型:

template <class> class OwnershipPolicy = RefCounted,

class ConversionPolicy = DisallowConversion,
模板
结构foo{};
模板
结构x{};
结构y{};
模板
结构z{};
//这两项都是有效的:
福阿;
富b;
//这些不是:
富科;
福德;
foo e;//z有两个模板参数,B必须只有一个
值得注意的是,这个习惯用法被称为“基于策略的设计”

template <class> class OwnershipPolicy = RefCounted,

class ConversionPolicy = DisallowConversion,
template <typename A, template <typename> class B>
struct foo {};

template <typename T>
struct x {};

struct y {};

template <typename T, typename U>
struct z {};

// both of these are valid:
foo<x<int>, x> a;
foo<y, x> b;
// these are not:
foo<y, x<int>> c;
foo<y, y> d;
foo<y, z> e; // z has two template arguments, B must have only one