Professional Web Applications Themes

MPCreateTask() and C++ member function - Mac Programming

Thanks to everybody who helped me with my previous queries on multiprocessing. This is a great group! I have another question, I hope someone can throw light on it. MPCreateTask() of MultiProcessing library takes as (one of the) parfameters a pointer to a function which executes as task. According to doentation, the task function should return OSStatus and accept a 32 bit pointer as argument. For example, a typical task function would look like: OSStatus MyTaskFunc(void* parameter) The question is: Can a C++ member function be passed as task function to MPCreateTask()? I tried but compiler complains that "no matches ...

  1. #1

    Default MPCreateTask() and C++ member function

    Thanks to everybody who helped me with my previous queries on
    multiprocessing. This is a great group!

    I have another question, I hope someone can throw light on it.

    MPCreateTask() of MultiProcessing library takes as (one of the)
    parfameters a pointer to a function which executes as task. According
    to doentation, the task function should return OSStatus and accept a
    32 bit pointer as argument. For example, a typical task function would
    look like:

    OSStatus MyTaskFunc(void* parameter)

    The question is: Can a C++ member function be passed as task function to
    MPCreateTask()? I tried but compiler complains that

    "no matches converting function `MyTaskFunc' to type `OSStatus (*)(void*)"

    I have searched everywhere, and all example code demonstrates
    MPCreateTask() in C using C function pointer.

    I am trying to do this in a C++ class that has a member function that
    calls MPCreateTask() and passes another member function from the same
    class as task function.

    Any help or pointers would be appreciated.

    ==============

    Asd Guest

  2. #2

    Default Re: MPCreateTask() and C++ member function

    In article <GL5hb.70996$%h1.53430sccrnsc02>, edu says... 

    That's because a member function won't have the signature 'OSSStatus (*)
    (void*)' it will be 'OSStatus (YourClass::*)(void*)'

    Ref: <http://www.parashift.com/c++-faq-lite/pointers-to-members.html>

     

    Make the member function static and it will work. Being static the
    function will not have access to non-static member variables but you can
    always add the 'this' pointer with whatever else is being munged up into
    the void* parameter.
    James Guest

  3. #3

    Default Re: MPCreateTask() and C++ member function

    James Weatherley wrote: 
    >
    >
    > That's because a member function won't have the signature 'OSSStatus (*)
    > (void*)' it will be 'OSStatus (YourClass::*)(void*)'
    >
    > Ref: <http://www.parashift.com/c++-faq-lite/pointers-to-members.html>
    >

    >
    >
    > Make the member function static and it will work. Being static the
    > function will not have access to non-static member variables but you can
    > always add the 'this' pointer with whatever else is being munged up into
    > the void* parameter.[/ref]

    Thanks! Your suggestion of static function and munging 'this' pointer
    with void* parameter did the trick.

    ====================

    Asd Guest

Similar Threads

  1. Replies: 1
    Last Post: November 7th, 02:18 AM
  2. Replies: 1
    Last Post: March 3rd, 01:03 PM
  3. Replies: 2
    Last Post: September 29th, 09:15 AM
  4. member.rect does not work member.regpoint does
    By Nick in forum Macromedia Director Lingo
    Replies: 1
    Last Post: August 27th, 01:01 PM
  5. checking the return value of member function with empty
    By Edward Rudd in forum PHP Development
    Replies: 2
    Last Post: August 10th, 06:46 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139