开发者

what is the problem of this code in c++

开发者 https://www.devze.com 2023-03-03 13:28 出处:网络
template <typename T> class Foo { T tVar; public: Foo(T t):tVar() {} }; class FooDerived: public Foo<st开发者_StackOverflow社区d::string> {};
template <typename T>
class Foo {
    T tVar;
    public:
    Foo(T t):tVar() {}
};

class FooDerived: public Foo<st开发者_StackOverflow社区d::string> {};

FooDerived fd;

what is the problem of this code?


the problem is Foo does not have an empty C'tor - Foo(void), while FooDerived is trying to initialize the Foo with an empty C'tor (since it is the default..) so you will get a compilation error, since the compiler does not know how to create DerivedFoo()

0

精彩评论

暂无评论...
验证码 换一张
取 消