开发者

IMPLEMENT_DYNCREATE, "Use MFC in a Static Library" and inheritance

开发者 https://www.devze.com 2023-01-15 16:21 出处:网络
If I switch my project from using MFC in a shared DLL to use MFC in a static library, the following code won\'t compile:

If I switch my project from using MFC in a shared DLL to use MFC in a static library, the following code won't compile:

class Test : public CObject
{
public:
    //DECLARE_DYNCREATE(Test); // If I uncomment this line, it works
};

class Test2 : public Test
{
public:
    DECLARE_DYNCREATE(Test2);
};

IMPLEM开发者_运维百科ENT_DYNCREATE(Test2, Test); // <-- error C2039: 'classTest' : is not a member of 'Test'

Though, if I uncomment DECLARE_DYNCREATE(Test), it works. I can't find anything in the docs saying the base class must use DECLARE_DYNCREATE, or that there is a difference between linking statically or shared.

The problem is I have some thirdparty code which doesn't use the DYNCREATE macros. Does anyone know why the requirements differs when linking statically, and if there is a way to get around this without declaring the base class with DECLARE_DYNCREATE?

Thanks.


If you use IMPLEMENT_DYNCREATE, you need it's companion DECLARE_DYNCREATE too. And you have to use the implement with class and base_class, in your example:

IMPLEMENT_DYNCREATE(Test,CObject);

But I wonder if you need dynamic creation for a CObject-derived class at all. Any reason for this?

0

精彩评论

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