views:

625

answers:

2

.NET Framework 3.5 comes with all the LINQ goodies, and also includes predefined generic Func and Action delegates. They are generic for up to 4 arguments. I am writing a C++/CLI project that (unfortunately) uses VS 2005 and must only rely on the standard 2.0 assembly set (so no System.Core).

I tried defining my own generic delegates (in my own namespace) to make future ports easier, by the compiler chokes on this (multiple definitions). Any suggestions?

delegate void Action();

generic <typename Arg1>
delegate void Action(Arg1 arg1);
+1  A: 

I'm guessing here but I think your best bet is to define only those delegates in a C# assembly. C++/CLI has no problem making use of such a family of overloaded generics, but doesn't seem to be able to define them.

Daniel Earwicker
A: 

Delegates in C++/CLI are considered classes and not functions. In C++ you're not allowed to have a templated and non-templated version of the same class (although you are allowed to have templated and non-templated versions of a single function, so long as overloading is possible based on the arguments passed to the function).

It is possible to create a templated class and then specialize it for certain types. This may get you close to what you're looking for.

Max Lybbert