Reputation: 1866
I know it is possible to define default values for template parameters:
template<int N = 10> struct Foo {};
You can use this like Foo<>
for example, but I want to be able to write just Foo
.
I tried the following, but it doesn't work (throws compiler exception):
struct Foo : Foo<10> {};
Is this possible in C++?
Upvotes: 1
Views: 251
Reputation: 12907
You can't directly, but can achieve something close thanks to a typedef
, i.e.
template<int N = 10> struct Foo{};
typedef Foo<> DefaultFoo;//Or whatever name that fits, just not 'Foo'
int main() {
DefaultFoo myFoo;
return 0;
}
Upvotes: 1