C++ virtual (sealed) function

自作多情 提交于 2019-12-10 17:36:35

问题


I am using classes from a dll in my C++ project. All is working fine, until...

When trying to call a certain method (listed in the object browser), I am getting an error that this method is not a member of the namespace.

Upon investigation, I noticed that this method is listed as "virtual void x() sealed".

Is there a way to make a call to such a function?


回答1:


For future reference, I just received a response from the enterprise library support team. They posted a link to the following:

Managed C++ and IDisposable I'm writing some code using the new Managed C++/CLI syntax and I ran into this error:

error C2039: 'Dispose' : is not a member of 'System::IDisposable'

the code I started with was this:

image->Dispose(); // image implements IDisposable

which gave me the same compiler error, so I wanted to eliminate a class/namespace error so I rewrote it as this:

((IDisposable ^)image)->Dispose();

Which gave the above error. Yikes!

Here's the fix:

use delete. Managed C++ now hides Dispose() inside the finalizer. Just delete the object, it handles the rest. Freaky.

This really works!!!!




回答2:


Sealed in a C++ CLI keyword (managed C++) specific to .NET and not C++ in general.

sealed on a function means that you can't override that method in a derived type.

sealed does not mean that you can't call the function, I'm guessing your function is private.




回答3:


I don't see why it being virtual and sealed should in itself prevent you from calling the function. According to MSDN, the sealed keyword is specifically meant for virtual methods anyway.

Is there any more information you can give about the function in question and how you are trying to use it?



来源:https://stackoverflow.com/questions/2260055/c-virtual-sealed-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!