Re: Forward declaration of C# types in managed C++ headers

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



You can add your C# assembly in a project's references thus you may not
import it explicitly.
--
Vladimir Nesterovsky
e-mail: vladimir@xxxxxxxxxxxxxxxxxxxx
home: http://www.nesterovsky-bros.com

> I'm working with C# objects from managed C++ using the gcroot template.
>
>
> There'a a C++ header containing the definition of a C++ class:
>
> #using <mscorlib.dll>
> #include <vcclr.h>
> #using <CSharpModule.dll>
>
> class CPlusPlusClass
> {
> ....
>
> gcroot<TLNameSpace::SubNameSpace::SomeType*> _csharpInstance;
>
> ....
> }
>
>
> and a C++ source file containing the class definition
>
>
> #include "CPlusPlusClass.h"
> using namespace TLNameSpace::SubNameSpace;
>
>
> void CPlusPlusClass::createCSharp()
> {
> gcroot = new SomeType();
> }
>
> void CPlusPlusClass::doSomething()
> {
> gcroot->someCSharpMethod();
> }
>
> .....
>
>
> In this example, I need the #using <CSharpModule.dll> directive in the C++
> header. One way to avoid this is
> to split CPlusPlusClass into CPlusPlusInterface and CPlusPlus
> Implementation.
> A more elegant technique in C++ would be a forward declaration for
> TLNameSpace::SubNameSpace::SomeType in
> the C++ header. However, I didn't find out how to do this.
> The most promising try was
>
> namespace TLNameSpace {
> namespace SubNameSpace {
> __gcc class SomeType;
> }
> }
>
> At least the header compiled. On the #using <CSharpModule.dll> line, I got
> an 'already defined' error.
> Obviously C++ and C# namespaces are just a little bit the same ....
>
> My question is:
>
> - Is there a way to do the forward declaration described above ?
>
>
> I'd appreciate any hint/solution for this


.



Relevant Pages

  • Re: Newbie and seventy-two-bie, please help.
    ... are using or bring the names into the global namespace. ... Prefer putting each declaration on its own line and adding a comment for ... definition goes into a header file called for example pool.h and rest goes ... mainalways returns an int. ...
    (alt.comp.lang.learn.c-cpp)
  • Forward declaration again
    ... >>> I'm working with C# objects from managed C++ using the gcroot template. ... >> using namespace TLNameSpace::SubNameSpace; ... >> to split CPlusPlusClass into CPlusPlusInterface and CPlusPlus Implementation. ... >> __gcc class SomeType; ...
    (microsoft.public.dotnet.languages.vc)
  • Forward declaration of C# types in managed C++ headers
    ... to split CPlusPlusClass into CPlusPlusInterface and CPlusPlus Implementation. ... namespace SubNameSpace {__gcc class SomeType;} ...
    (microsoft.public.dotnet.languages.vc)