带有继承析构函数的警告 C4710(未内联)

发布于 2024-10-21 04:45:23 字数 1143 浏览 5 评论 0原文

我有 3 个类构建继承链。其中两个类是纯抽象的(IProxy 和 IDataProxy),第三个类真正“完成工作”(DataProxy)。这些类如下(此处仅显示 con/析构函数):

IProxy:

class __declspec(dllexport) IProxy
{
public:
    IProxy() {}
    virtual ~IProxy() {}
};

IDataProxy:

class __declspec(dllexport) IDataProxy : public IProxy
{
public:
    IDataProxy() {}
    virtual ~IDataProxy() {}
};

DataProxy 标头:

class __declspec(dllexport) DataProxy : public IDataProxy
{
public:
    DataProxy();
    virtual ~DataProxy() {}
};

DataProxy 实现文件:

DataProxy::DataProxy() : m_operationType( eUnknown )
{}

当我使用 Microsoft C++ 编译器(版本 12.00.8804)编译类 DataProxy 时,我收到以下警告:

警告 C4710:函数“virtual __thiscall IDataProxy::~IDataProxy(void)”未内联
警告 C4710:函数“virtual __thiscall IDataProxy::~IDataProxy(void)”未内联
警告 C4710:函数“virtual __thiscall DataProxy::~DataProxy(void)”未内联
warning C4710: function 'virtual __thiscall DataProxy::~DataProxy(void)' not inlined

我真的不知道这些警告来自哪里。我从未告诉编译器内联任何内容。我不知道如何摆脱这些警告。

谁能解释一下这些警告?多谢!

此致, 奥利弗

I have 3 classes that build a chain of inheritance. Two of the classes are pure abstract (IProxy and IDataProxy), the third one really "does the work" (DataProxy). The classes are the following (only showing con/destructors here):

IProxy:

class __declspec(dllexport) IProxy
{
public:
    IProxy() {}
    virtual ~IProxy() {}
};

IDataProxy:

class __declspec(dllexport) IDataProxy : public IProxy
{
public:
    IDataProxy() {}
    virtual ~IDataProxy() {}
};

DataProxy Header:

class __declspec(dllexport) DataProxy : public IDataProxy
{
public:
    DataProxy();
    virtual ~DataProxy() {}
};

DataProxy Implementation file:

DataProxy::DataProxy() : m_operationType( eUnknown )
{}

When I compile the class DataProxy with Microsoft C++ compiler (version 12.00.8804) I get the following warnings:

warning C4710: function 'virtual __thiscall IDataProxy::~IDataProxy(void)' not inlined
warning C4710: function 'virtual __thiscall IDataProxy::~IDataProxy(void)' not inlined
warning C4710: function 'virtual __thiscall DataProxy::~DataProxy(void)' not inlined
warning C4710: function 'virtual __thiscall DataProxy::~DataProxy(void)' not inlined

I don't really know where these warnings com from. I never told the compiler to inline anything. And I don't have any idea how to get rid of these warnings.

Can anyone shed some light on these warnings? Thanks a lot!

Best regards,
Oliver

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

铃予 2024-10-28 04:45:23

通过在类内部定义构造函数,您可以隐式添加 inline 说明符。虚函数(包括析构函数)不是内联的。

然而,警告肯定来自这样一个事实:dllexport 函数必须具有给定的 (thiscall) 调用约定,因此永远不会被内联。如果虚拟成员函数以非多态方式调用,则可以内联它们。这里永远不会出现这种情况。

@MSalters 的注释提供了为什么 IProxy::~IProxy() 不会出现警告的提示。

要消除警告,请在源文件中定义空的析构函数。

By defining the constructors inside the class, you implicitly add the inline specifier. Virtual functions (including destructors) are not inlined.

However the warning most certainly comes from the fact that a dllexport function must have a given (thiscall) calling convention and therefore will never be inlined. Virtual member functions can be inlined if they are called non polymorphically. This will never be the case here.

@MSalters 's comment provides a hint to why the warning does not occur for IProxy::~IProxy().

To get rid of the warning, define your empty destructors in the source file.

薄荷港 2024-10-28 04:45:23

通过在类中提供析构函数的实现,您要求内联它们。对于构造函数和成员函数也是如此。

By providing the implementation of the destructors in the class, you are asking to inline them. This is also true for constructors and members functions.

知足的幸福 2024-10-28 04:45:23

http://msdn.microsoft.com/en- us/library/yd3056cz(v=VS.100).aspx

此链接清楚地解释了您需要了解的所有内容。它清楚地说明了警告是什么、为什么会发生以及默认情况下警告处于关闭状态。如果内联定义,则类成员函数是隐式内联的。在提出问题之前通常需要付出一些努力,例如在编译器文档中搜索警告号。

http://msdn.microsoft.com/en-us/library/yd3056cz(v=VS.100).aspx

This link clearly explains everything you need to know. It clearly states what the warning is, why it occurs, and that the warning is off by default. Class member functions are implicitly inline if defined inline. A little effort before asking a question is generally required- such as searching your compiler's documentation for the warning number.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文