E
Eckart Haug
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
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