Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.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++ C+中模板化别名的Typedef+;_C++_C++11_Templates_Vector_Alias - Fatal编程技术网

C++ C+中模板化别名的Typedef+;

C++ C+中模板化别名的Typedef+;,c++,c++11,templates,vector,alias,C++,C++11,Templates,Vector,Alias,我有一个模板类a: template<template<typename>class VectorT> class A { //... } template<template<typename>class VectorT> class A { public: template<typename T> using Vector = VectorT<T>; //... }

我有一个模板类
a

template<template<typename>class VectorT>
class A
{
      //...
}
template<template<typename>class VectorT>
class A
{
 public:
      template<typename T>
      using Vector = VectorT<T>;

      //...
}
我决定在
A
内部创建一个名为
Vector
的别名:

template<template<typename>class VectorT>
class A
{
      //...
}
template<template<typename>class VectorT>
class A
{
 public:
      template<typename T>
      using Vector = VectorT<T>;

      //...
}
例如,为了在类
B
中创建属性
Vector
。 因此,我尝试了三件事(在类内
B
):


我对
typedef
alias
之间的区别感到困惑,尤其是当我想将它们混合在一起,并且它们是模板化的…

类型3添加一个
模板

template <typename T>
using Vector = typename A::template Vector<T>;
模板
使用Vector=typename A::template Vector;

为了澄清您对
typedef
(C++98)和别名声明(C++11)之间区别的困惑:区别在于模板

别名声明可以模板化,而typedef不能模板化。

使用
using
使用用户定义的分配器将myvector声明为向量:

template<typename T>
using myvector = std::vector<T, myAllocator<T>>  // alias declaration

myvector<int> myIntVector; // client code
::type
后缀很麻烦,使用
编写的样板文件更少。这就是为什么您更喜欢别名声明而不是typedef

template <typename T>
using Vector = typename A::template Vector<T>;
template<typename T>
using myvector = std::vector<T, myAllocator<T>>  // alias declaration

myvector<int> myIntVector; // client code
template<typename T>
struct myvector {
    typedef std::vector<T, myAllocator<T>> type;
}

myvector<int>::type myIntVector; // client code