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++?
You can't directly, but can achieve something close thanks to a typedef
, ie
template<int N = 10> struct Foo{};
typedef Foo<> DefaultFoo;//Or whatever name that fits, just not 'Foo'
int main() {
DefaultFoo myFoo;
return 0;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.