Is there any compile switch that could turn all old C++ code into managed class?

  • Thread starter Thread starter Lei Jiang
  • Start date Start date
L

Lei Jiang

If I have to add __gc in every class, it would be a huge work. Is there any
option that could compile all C++ class into manganged class without modify
any source code?
 
Lei Jiang said:
If I have to add __gc in every class, it would be a huge work. Is there any
option that could compile all C++ class into manganged class without modify
any source code?

Just doing a Find/Replace for 'class' won't work - there's too many
differences in what you can do in managed/unmanaged classes that would make
that impossible. That's why you can compile managed and unmanaged C++ into
the same assembly - it means you don't need to convert everything all at
once but can do it as you have time. If you compile with the /CLR switch,
most stuff will get compiled into managed code, even though the classes
themselves aren't managed.

There may be refactoring tools out there tha can do this (or you could write
one) but I think it would be extremely hard to write such a tool.

Steve
 
Lei Jiang said:
If I have to add __gc in every class, it would be a huge work. Is there any
option that could compile all C++ class into manganged class without modify
any source code?

Nope, sorry. life is not that simple ;-)

Further, I do not think that just by adding a __gc you can "convert"
your classes into managed classes. THere are many conceptual
differences that you just have to handle. For example, code that
instantiates any of your class objects on the stack will fail under
the managed version (you always create managed class instances on the
heap) and so on....

Two choices:

1. write a managed wrapper for each of your class
2. If you think adding a __gc will solve your problem (maybe you have
analysed the problem and figured that all you need is a __gc), in
which case, you can try adding a preprocessor definition like

#define class public __gc class

although I can bet a 100 bucks that #2 will just not work.

hth.
-Vinayak
 
Back
Top