Home > Imported Posts > Now for some Managed C++

Now for some Managed C++

March 23rd, 2005

I’ve been doing vanilla C# for some time now. (For the uninitiated, thats read as C sharp – as in music. If you say C hash or C pound, they will kill you.) The latest being some Windows.Forms. While this has been interesting, it looks like its now time to move on to some more exciting stuff. I started reading up a bit on Managed extensions to C++ today. And I thought, what the hell, its something to fill up my blog with. Most of the stuff you will find here can be found elsewhere too. “MSDN?” you ask. Yes.

The philosophy behind managed C++ seems to be this:

You have a legacy C++ library, do you? And is that holding you from writing a .net app? Don’t let it.

Since interop is what this really is for, there have to be two sides to it. One side that can talk to your legacy C++ (which is just regular C++), and the other side that can talk to the Common Language Runtime (CLR). This other side is the “managed extension” part of it. Which to a programmer means that we have some new syntax and some new semantics. The biggest noticeable change in managed C++, as compared to standard C++, is the ability to utilize the garbage collection provided by the CLR and to make use of the .net library.

Consider an example of the syntax change. There is now a new keyword called __gc. So if you want to create a class which gets “managed” by the CLR, here’s how you would define it.

#using <mscorlib.dll>

__gc class GCExample
{
};

And… it magically becomes managed. With the GC at your service, you no longer have to call delete on objects of this class.

More to come…

  1. No comments yet.
  1. No trackbacks yet.