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
당신이 방법'bar'을 의미합니까 :
당신은 여기template
규정해야합니까? – pippin1289코드에는'foo'가 없습니다. 그리고 당신의 코드는 Clang 3.4에서 잘 컴파일됩니다. – 0x499602D2
gcc 4.7.2에서'-std = C++ 0x'를 사용해도 정상적으로 컴파일됩니다. – Chnossos