Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Delegates in Managed C++

Delegates in Managed C++

Scheduled Pinned Locked Moved Managed C++/CLI
c++help
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    ptr_Electron
    wrote on last edited by
    #1

    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.

    D 1 Reply Last reply
    0
    • P ptr_Electron

      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.

      D Offline
      D Offline
      Dave Doknjas
      wrote on last edited by
      #2

      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

      P 1 Reply Last reply
      0
      • D Dave Doknjas

        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

        P Offline
        P Offline
        ptr_Electron
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups