How do I forward declare a delegate in C++/CLI?

B

brooder

None of the following seems to work:

delegate MyDelegate;

ref class MyDelegate;

public delegate void MyDelegate(Object ^sender, MyArgs ^args);

delegate void MyDelegate(Object ^sender, MyArgs ^args);
 
J

Jochen Kalmbach [MVP]

Hi brooder!
public delegate void MyDelegate(Object ^sender, MyArgs ^args);

This works... you only need to forward-declare the types!

The following works perfectly:

// forward:
ref class MyArgs;

// delegates:
public delegate void MyDelelage(Object^ sender, MyArgs^ args);


Of course, the error message which comes up if you forget the forward is
very strange:
1>.\MCPP_Console_2008.cpp(328) : error C2059: syntax error : 'public'



--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
B

brooder

Hi Jochen,

The following works for declaration:

public delegate void MyDelegate(Object ^sender, MyArgs ^args);

But using it as a "forward" declaration (if at all it is possible)
gives me

error C3756: 'MyNameSpace::MyDelegate': delegate definition conflicts
with an existing symbol

Here is what I am trying to do:
I have several classes and some delegates declared in a header file
file1.h.
In file2.h I have forward declared a few of the classes I am using.
However I am also using MyDelegate in file2.h and would like to
declare it.
The error C3756 occurs because I am including file1.h in file2.cpp.

Aren't delegates types?

The same question on Stack Overflow: http://stackoverflow.com/questions/1005892
--

Thanks

Agnel

http://corner-house.blogspot.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top