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

  • Thread starter Thread starter brooder
  • Start date Start date
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);
 
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/
 
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
 
Back
Top