2014-04-04 6 views
2

이 동작을 구현하는 방법은 무엇입니까? 내가 variadically (내 경우에만 정수에) 다른 유형 템플릿되는 방법 foo 포함 된 MyClass을 템플릿 한 -가변적으로 템플릿 화 된 클래스의 템플릿 메서드

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


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

}; 

은 내가 필요한 것은 이것이다. 이것은 가능한가? 내가 simmilar 솔루션을 발견했지만 비 variadic 클래스에만.

그러나 bar으로 인해 컴파일 할 수 없습니다.

편집 : GCC에서 컴파일 4.7.2

한 사람이 가능성이 제발 도움이 될이 MyClass<int, int>::bar<4>()

같은 방법을 실행해야합니까? 사전에

감사

EDIT2 : 전체 코드

#include <stdio.h> 
#include <stdlib.h> 
#include <math.h> 
#include <queue> 
#include <set> 
#include <vector> 
#include <string> 
#include <cstring> 
#include <algorithm> 
#include <stack> 
#include <map> 

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


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

}; 

template < class A, int N > 
static void foo() 
{ 
    A::bar <N>(); 
} 


int main() { 

    foo< MyClass<int, int>, 4>(); 

    return 0; 
} 

EDIT3 : 오류

$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 
+1

당신이 방법'bar'을 의미합니까 :

당신은 여기 template 규정해야합니까? – pippin1289

+1

코드에는'foo'가 없습니다. 그리고 당신의 코드는 Clang 3.4에서 잘 컴파일됩니다. – 0x499602D2

+0

gcc 4.7.2에서'-std = C++ 0x'를 사용해도 정상적으로 컴파일됩니다. – Chnossos

답변

2

문제는 당신이를 명확하게하는하지 않고 템플릿 내에서 템플릿 메소드를 호출하고 있다는 것입니다 구문을 템플릿 호출로 사용합니다 (자세한 설명은 duplicate 참조).

A::template bar<N>(); 
관련 문제