Ask Your Question
0

How can the warning for delete-non-virtual-dtor be turned off while using a protected non-virtual destructor?

asked 2021-10-12 11:00:00 +0000

devzero gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-12-28 11:00:00 +0000

nofretete gravatar image

One way to turn off the warning for delete-non-virtual-dtor is to use a pragma statement. For example, the following code disables the warning for MSVC compiler:

#pragma warning(disable: 4265)

class MyBaseClass
{
protected:
    ~MyBaseClass() {} // protected non-virtual destructor
};

#pragma warning(default: 4265)

This will suppress the warning for delete-non-virtual-dtor specifically for the MyBaseClass destructor. However, it is recommended to consider using a virtual destructor instead of a protected non-virtual destructor to avoid potential issues with object deletion in the future.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-10-12 11:00:00 +0000

Seen: 7 times

Last updated: Dec 28 '21