“this->模板[somename]”的调用是什么? [英] What does a call to 'this->template [somename]' do?

查看:104
本文介绍了“this->模板[somename]”的调用是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索过这个问题,我找不到任何东西。有没有更好的方法来查询这样的在谷歌或任何人可以提供链接或链接或相当详细的解释?谢谢!

I've searched for this question and I can't find anything on it. Is there a better way to query something like this in Google or can anyone provide a link or links or a fairly detailed explanation? Thanks!

编辑:这是一个示例

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;
   } 
};

此示例来自 ndarray 项目,而不是我自己的代码。

This example is from the ndarray project on Google Code and is not my own code.

推荐答案

其中 this->模板是必需的。它不是真的匹配OP的例子虽然:

Here is an example where this->template is required. It doesn't really match the OP's example though:

#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();
}

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

In this example the this is needed because otherwise alloc would not be looked up in the base class because the base class is dependent on the template parameter T. The template is needed because otherwise the "<" which is intended to open the template parameter list containing 200, would otherwise indicate a less-than sign ([temp.names]/4).

这篇关于“this-&gt;模板[somename]”的调用是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆