简体   繁体   English

编译器错误lnk2019和c4930使用继承

[英]Compiler error lnk2019 and c4930 using inheritance

I'm having an issue compiling my code when I'm using inheritance. 当我使用继承时,我遇到了编译代码的问题。 I've tried most of everything but no luck compiling 我已经尝试了大部分内容,但没有运气编译

I first have an abstract or 'interface' class 我首先有一个抽象或'接口'类

class ImyBase
{
    public:
        ImyBase();
        ImyBase(....);
        virtual ~ImyBase();

        virtual void someFuncs() = 0;
        ....
};

Then I have a class that implements this class. 然后我有一个实现这个类的类。

class myBase : public ImyBase
{
    public:
        myBase();
        myBase(....);
        virtual ~myBase();

        void someFuncs();
        ....
};

Then I have a wrapper class. 然后我有一个包装类。

class myWrap
{
    public:
        myWrap();
        myWrap(....);
        virtual ~myWrap();

        void someFuncs();
        ....
};

Everything works good in the implementation at this point. 在这一点上,一切都很好。 But when I try to test the wrapper class, that's where I get the error LNK2019: unresolved external symbol "public: __thiscall ImyBase::ImyBase(void)" (??0ImyBase@@QAE@XZ) referenced in function "public: __thiscall myBase::myBase(void)" (??0myBase@@QAE@XZ) 但是当我尝试测试包装类时,我得到的错误是LNK2019:未解析的外部符号“public:__thiscall ImyBase :: ImyBase(void)”(?? 0ImyBase @@ QAE @ XZ)在函数“public:__thiscall”中引用myBase :: myBase(void)“(?? 0myBase @@ QAE @ XZ)

int main(int argc, char* argv)
{
    myWrap wr;
}

Any help is appreciated! 任何帮助表示赞赏! I know its gotta be a dum mistake somewhere... 我知道它必须是某个地方的傻瓜......

You have no implementation for the base constructor. 您没有基础构造函数的实现。 The options are defining the constructors in an implementation file or, if they're empty, in the class definition itself: 选项是在实现文件中定义构造函数,或者如果它们是空的,则在类定义本身中定义:

class ImyBase
{
    public:
        ImyBase() {};
        ImyBase(....) {};
        virtual ~ImyBase() {};
};

or mark them as default for C++11: 或将它们标记为C ++ 11的default

class ImyBase
{
    public:
        ImyBase() = default;
        ImyBase(....) = default;
        virtual ~ImyBase() = default;
};

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

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