0

Gcc (4.7.2) は、このコードのコンパイル中に小さなエラーをスローします:

#include <iostream>

template<typename T>
struct test
{
    template<int n>
    int select() const
    {
        return n;
    }
};

template<typename T>
struct test_wrapper
{
    void print() const
    {
        std::cout << t.select<3>() << std::endl; // L.18
    }

    test<T> t;
};

int main()
{}

エラーは次のとおりです。

test3.cpp: In member function 'void test_wrapper<T>::print() const':
test3.cpp:18:34: error: expected primary-expression before ')' token

test<T> tたとえば、特殊なタイプで変更するとtest<void> t、このエラーは消えます。

問題はどこだ?

4

1 に答える 1

7

templateテンプレート化されたコンストラクト内でテンプレート メソッドを呼び出す場合は、キーワードを使用する必要があります。

t.template select<3>();
于 2013-01-29T17:28:08.903 に答える