繁体   English   中英

在C ++中定义模板类的默认实现

[英]Define default implementation of template class in C++

我知道可以为模板参数定义默认值:

template<int N = 10> struct Foo {};

例如,您可以像Foo<>这样使用它,但我希望只写Foo

我尝试了以下操作,但是不起作用(抛出编译器异常):

struct Foo : Foo<10> {};

这在C ++中可能吗?

您不能直接使用,但是可以通过typedef接近实现,即

template<int N = 10> struct Foo{};

typedef Foo<> DefaultFoo;//Or whatever name that fits, just not 'Foo'

int main() {
    DefaultFoo myFoo;
    return 0;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM