IMPLMENT_DYNCREATE, “在静态库中使用 MFC”和继承
如果我将我的项目从在共享 DLL 中使用 MFC 切换为在静态库中使用 MFC,则以下代码将无法编译:
class Test : public CObject
{
public:
//DECLARE_DYNCREATE(Test); // If I uncomment this line, it works
};
class Test2 : public Test
{
public:
DECLARE_DYNCREATE(Test2);
};
IMPLEMENT_DYNCREATE(Test2, Test); // <-- error C2039: 'classTest' : is not a member of 'Test'
不过,如果我取消注释 DECLARE_DYNCREATE(Test),它就可以工作。我在文档中找不到任何内容说明基类必须使用 DECLARE_DYNCREATE,或者静态链接或共享链接之间存在差异。
问题是我有一些不使用 DYNCREATE 宏的第三方代码。有谁知道为什么静态链接时要求不同,以及是否有办法解决这个问题而不用 DECLARE_DYNCREATE 声明基类?
谢谢。
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);
};
IMPLEMENT_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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用
IMPLMENT_DYNCREATE
,您还需要它的配套DECLARE_DYNCREATE
。在您的示例中,您必须使用带有 class 和 base_class 的实现:但我想知道您是否需要动态创建 CObject 派生类。这有什么原因吗?
If you use
IMPLEMENT_DYNCREATE
, you need it's companionDECLARE_DYNCREATE
too. And you have to use the implement with class and base_class, in your example:But I wonder if you need dynamic creation for a CObject-derived class at all. Any reason for this?