开发者

what is the problem of this code in c++

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜