is there any way implementing this behaviour?
template < typename... Args >
class MyClass
{
public:
typedef std::tuple < Args... > my_tuple;
template < int n >
static int bar () { return -5; };
};
What I need is this - I have variadically templated MyClass
that contains method foo
which is templated by another type (in my case only integer). Is this even possible? I have found simmilar solution but only for non-variadic class.
But this can't be compiled due to bar
.
EDIT: I compile on gcc 4.7.2
One should run the method like this MyClass<int, int>::bar<4>()
Could anyone possibly help me please?
Thanks in advance
EDIT2: full code
#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: error
$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