none
Passing a System::Object^ from a returned variable RRS feed

  • Question

  • I have a singleton class thet has a function A^ A::Instance();

    I'm trying to pass this to an EventHandler as an object and I get the folowing error

    Error 4 error C2664: 'System::EventHandler::Invoke' : cannot convert parameter 1 from 'A^(__clrcall *)(void)' to 'System::Object ^'

    for  example I have an event

    public event EventHandler TestEvent

    and then I'm trying to call TestEvent(A::Instance, nullptr);

     

    Thanks,


    Keith
    Thursday, May 19, 2011 6:35 PM

Answers

  • You're passing A::Instance, which is a function pointer, into an object expecting an Object^.

     

    Try adding the parenthesis:

    TestEvent(A::Instance(), nullptr);


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Proposed as answer by eryang Friday, May 27, 2011 6:12 AM
    • Marked as answer by eryang Tuesday, May 31, 2011 7:42 AM
    Thursday, May 19, 2011 7:16 PM
    Moderator

All replies

  • You're passing A::Instance, which is a function pointer, into an object expecting an Object^.

     

    Try adding the parenthesis:

    TestEvent(A::Instance(), nullptr);


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Proposed as answer by eryang Friday, May 27, 2011 6:12 AM
    • Marked as answer by eryang Tuesday, May 31, 2011 7:42 AM
    Thursday, May 19, 2011 7:16 PM
    Moderator
  • We temporarily mark a reply since the thread idle for a long time, please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.


    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, May 31, 2011 7:42 AM