问题
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