C++ 可变模板类中的模板化方法

C++ 可变模板类中的模板化方法,c++,class,templates,methods,variadic-templates,C++,Class,Templates,Methods,Variadic Templates,有没有办法实现这种行为 template < typename... Args > class MyClass { public: typedef std::tuple < Args... > my_tuple; template < int n > static int bar () { return -5; }; }; 编辑3:错误 $g++ -Wall -std=c++11 -g -o test.out test.cpp

有没有办法实现这种行为

template < typename... Args >
class MyClass
{
public:
    typedef std::tuple < Args... > my_tuple;


    template < int n >
    static int bar () { return -5; };

};
编辑3:错误

$g++ -Wall -std=c++11 -g -o test.out test.cpp
test.cpp: In function ‘void foo()’:
test.cpp:28:16: error: expected primary-expression before ‘)’ token
test.cpp: In instantiation of ‘void foo() [with A = MyClass<int, int>; int N = 4]’:
test.cpp:34:30:   required from here
test.cpp:28:2: error: invalid operands of types ‘<unresolved overloaded function type>’ and ‘int’ to binary ‘operator<’
make: *** [test] Error 1
$g++-Wall-std=c++11-g-o test.out test.cpp
test.cpp:在函数“void foo()”中:
test.cpp:28:16:错误:在“')标记之前应该有主表达式
test.cpp:在“void foo()[with A=MyClass;int N=4]的实例化中:
测试。cpp:34:30:从这里开始需要

test.cpp:28:2:错误:类型为“”和“int”到二进制“运算符”的操作数无效问题在于,您从模板中调用模板方法时,没有消除作为模板调用的语法歧义(有关详细说明,请参阅)

此处需要
模板
限定符:

A::template bar<N>();
A::模板栏();

您的意思是方法
?您的代码中没有
foo
。您的代码在Clang 3.4 compiles上编译得很好,在gcc 4.7.2上编译得很好,带有
-std=c++0x
。您得到了什么错误?提供了完整的代码和错误,thanx伙计:)
A::template bar<N>();