473,396 Members | 1,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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
Nov 17 '05 #1
3 2224
You can add your C# assembly in a project's references thus you may not
import it explicitly.
--
Vladimir Nesterovsky
e-mail: vl******@nesterovsky-bros.com
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

Nov 17 '05 #2
Thanx for the quick reply. Your suggestion would mean that I'd have to add a C# reference to any C++ module
that includes the C++ header. There's lots of them and I'd (for the moment) like to have the C++ <-> C#
interface encapsulated in one C++ module.

Vladimir Nesterovsky wrote:
You can add your C# assembly in a project's references thus you may not
import it explicitly.
--
Vladimir Nesterovsky
e-mail: vl******@nesterovsky-bros.com
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


Nov 17 '05 #3
Thanx for the quick reply. Your suggestion would mean that I'd have to add a C# reference to any C++ module
that includes the C++ header. There's lots of them and I'd (for the moment) like to have the C++ <-> C#
interface encapsulated in one C++ module.

Vladimir Nesterovsky wrote:
You can add your C# assembly in a project's references thus you may not
import it explicitly.
--
Vladimir Nesterovsky
e-mail: vl******@nesterovsky-bros.com
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


Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Alexander Grigoriev | last post by:
Not quite new version of GCC that I have to use, craps with the following code: enum E; enum E { e }; That is, it doesn't accept forward declaration of enum. C++ standard text doesn't...
1
by: qazmlp | last post by:
Is it a good style to re-forward declare the types, which were already forward declared in base header file, in derived class header file? // base.h class addrClass; class base { public:...
6
by: Steven T. Hatton | last post by:
Should I be able to forward declare something from a namespace different from the current one? For example the following code compiles: //testdriver.hpp #ifndef TESTDRIVER_HPP #define...
2
by: Plok Plokowitsch | last post by:
After over a decade of programming in C++ I seem to have missed some substantial point (mental note: am I getting too old for this?). A little bit of help would be *very* appreciated. I'm trying...
1
by: Steve | last post by:
Can anyone explain why C++ .NET compiler throws error for the following code segment: // Forward declaration of ListViewItemComparer class public __gc class ListViewItemComparer ; public __gc...
1
by: Gustavo L. Fabro | last post by:
Greetings! Going directly to the point: myclass.h: //-------------------------------------- #pragma managed //Forward declaration
2
by: Carlos Martinez Garcia | last post by:
Hi all: I usually make forward declarations in headers. Something like this: class MyClass; Now, I need a reference to a type defined like this (traditional C Style): typedef struct {
1
by: toton | last post by:
Hi, I have two namespace contains class InkFrame and PrefDialog respectively. PrefDialog needs InkFrame to show the dialog over the frame. It also stores a pointer to InkFrame inside it. Now I...
6
by: Hunk | last post by:
Hi I have a question on usage of forward declarations of templates. While searching through this group , people suggested using forward declarations and typedefs for templates as // in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.