To be honest, I do not really know how to name that problem. I’ll just show the code that is not working:
template<int SIZE>
struct bar{
};
template<int SIZE>
struct foo{
template<int X>
void f(bar<X> b);
};
template<int SIZE, int X>
void foo<SIZE>::f(bar<X> b){
}
int main(){
foo<1> f;
bar<2> b;
}
I’d like to separate definition from implementation to avoid cyclic dependency issues. Separation is done in header files only, I don’t want to put template code into cpp files. Using pointers is no option in that case. Refactoring has been considered but is not a real option, either.
Implementing foo::f without a parameter that has template parameters itself is working fine. I do not really get the problem with that parameter, though.
Code should work using gcc 4.7 and (even more important) Visual Studio 2010. C++11 is ok as long as supported by the platforms mentioned.
Solutions, workarounds as well as theoretical explanations why I’m doing something completly wrong will be highly appreciated. TIA.
It is wrong syntax.
The correct syntax is to use
templatetwice as:Note that the order matters here.