Delegates in Managed C++
-
using namespace System::Runtime::InteropServices;
public ref class CTest
{
public:
static delegate bool Callback(int i);}
While compliting I get error. error C2144: syntax error : 'bool' should be preceded by ';' I would like to use delegate as a callback function and select one of the serval avaliable function. Please advice. thanks.
-
using namespace System::Runtime::InteropServices;
public ref class CTest
{
public:
static delegate bool Callback(int i);}
While compliting I get error. error C2144: syntax error : 'bool' should be preceded by ';' I would like to use delegate as a callback function and select one of the serval avaliable function. Please advice. thanks.
Remove the 'static' keyword - it's the cause of the error (and add a semi-colon after the class closing brace).
David Anton Convert between VB, C#, C++, & Java www.tangiblesoftwaresolutions.com
-
Remove the 'static' keyword - it's the cause of the error (and add a semi-colon after the class closing brace).
David Anton Convert between VB, C#, C++, & Java www.tangiblesoftwaresolutions.com
Thanks a lot it worked. :) Basically I need an advice. I am woking in dot net managed C++ . I had a very large switch statement with about 50 cases now I am refactoring the switch case. putting each case in a function and using a delagate as callback and
main ()
{
switch (ivar)
{
case 1:
{
//somecode 1;
break;
}
case 1:
{
//somecode 2;
break;
}so on case 50: { //somecode 50; break } }
}
And now I am writing function
void somecode1(int a, int b)
{
somecode 1;
}
void somecode2(int a, int b)
{
somecode 2;
}
void somecode3(int a, int b)
{
somecode 50;
}static void Parse(int iType) { FunList entry = m\_FunList\[iType\]; entry.m\_Callback.Invoke(); } static void Main(string\[\] args) { Init(); //i=dynamic from 1 to 50 i=7 Parse(i); } static void Init() { //Inilize the FunList //set paramenters and function as properties }
Can you please correct me if I am doing some thing not correct? Is there any pattern that suits better? Thanks
modified on Wednesday, November 24, 2010 11:21 PM