Welcome to Atalasoft Community Sign in | Join | Help

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.

Published Friday, August 01, 2008 9:40 AM by Steve Hawley

Comments

Wednesday, August 06, 2008 11:45 PM by DotNetKicks.com

# Managed C and IDisposable

You've been kicked (a good thing) - Trackback from DotNetKicks.com

Anonymous comments are disabled