对'this-> template [somename]'的调用是做什么的?

Phi*_*oud 23 c++ templates

我已经搜索过这个问题但我找不到任何相关内容.有没有更好的方法在Google中查询这样的内容,或者任何人都可以提供链接或链接或相当详细的解释?谢谢!

编辑:这是一个例子

template< typename T, size_t N>
struct Vector {
public:
   Vector() {
       this->template operator=(0);
   }

   // ...       

   template< typename U >
   typename boost::enable_if< boost::is_convertible< U, T >, Vector& >::type operator=(Vector< U, N > const & other) {
       typename Vector< U, N >::ConstIterator j = other.begin();
       for (Iterator i = begin(); i != end(); ++i, ++j)
           (*i) = (*j);
       return *this;
   } 
};
Run Code Online (Sandbox Code Playgroud)

此示例来自Google Code上的ndarray项目,而不是我自己的代码.

How*_*ant 50

这是一个this->template需要的例子.它与OP的例子并不完全匹配:

#include <iostream>

template <class T>
struct X
{
    template <unsigned N>
        void alloc() {std::cout << "alloc<" << N << ">()\n";}
};

template <class T>
struct Y
    : public X<T>
{
    void test()
    {
        this->template alloc<200>();
    }
};

int main()
{
    Y<int> y;
    y.test();
}
Run Code Online (Sandbox Code Playgroud)

在这个例子中,this需要它,因为否则alloc不会在基类中查找,因为基类依赖于模板参数T.这template是必要的,因为否则打开包含200的模板参数列表的"<"将指示小于号([temp.names]/4).