C
chris
I want to implement a class with a variable number of template
parameters, but g++ claims this is not allowed. I believe however I can
emulate multiple parameters with the code below. While this seems to
work I just want to check it is correct, as it seems a little strange (A
give a default parameter, and that then activates a different
specialisation).
#include<stdio.h>
class dummy_class{};
template <class T1,class T2=dummy_class>
struct foo {
foo() {printf("2 parameters\n");}
};
template <class T1>
struct foo<T1,dummy_class> {
foo() {printf("1 parameter\n");}
};
int main(void) {
foo<int> a;
foo<int,int> b;
}
parameters, but g++ claims this is not allowed. I believe however I can
emulate multiple parameters with the code below. While this seems to
work I just want to check it is correct, as it seems a little strange (A
give a default parameter, and that then activates a different
specialisation).
#include<stdio.h>
class dummy_class{};
template <class T1,class T2=dummy_class>
struct foo {
foo() {printf("2 parameters\n");}
};
template <class T1>
struct foo<T1,dummy_class> {
foo() {printf("1 parameter\n");}
};
int main(void) {
foo<int> a;
foo<int,int> b;
}