No matching function call when passing member function of a class to pthread_cleanup_push()

tzippy

When I try to pass my function cleanup_thread() to pthread_cleanup_push():

pthread_cleanup_push(cleanup_thread, arg);

I get the following compiler error:

 error: no matching function for call to ‘__pthread_cleanup_class::__pthread_cleanup_class(<unresolved overloaded function type>, void*&)’

I guess its because void cleanup_thread(void *arg) is a member function of my class and therefor has the this pointer as first argument. So the signature of the function cleanup_thread() does not match. How can I tell pthread_cleanup_push() to use my member function cleanup_thread()?

Some programmer dude

The easiest solution is probably to make the function a static member function, and pass the instance pointer as the argument.

Something like this:

struct data_struct
{
    some_class* instance;
    pthread_t   thread_id;
};

class some_class
{
public:
    ...

    static void cleanup_thread(void* arg)
    {
        data_struct* ptr = reinterpret_cast<data_struct*>(arg);
        ptr->instance->private_cleanup_thread();
        delete ptr;
    }

private:
    void private_cleanup_thread()
    {
        ...
    }
};

...

some_class* some_class_ptr = new some_class;

...

data_struct* data_ptr = new data_struct;
data_ptr->instance = some_class_ptr;
data_ptr->thread_id = some_thread_id;

pthread_cleanup_push(&some_class::cleanup_thread, data_ptr);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

No matching function call when passing member function of a class to pthread_cleanup_push()

From Dev

No Matching Member Function to Call 'connect' - When Using 'this'

From Dev

Call member function when class type is not known

From Dev

no matching member function for call to 'insert'

From Dev

"is not a member of" and "no matching function for call to" errors

From Dev

No matching function for call to [class]

From Dev

No matching function for call to 'class'

From Dev

Calling sort() on a vector that's a member of a class "No matching function for call to swap()"

From Dev

"No matching member function for call to push" in Priority Queues C++

From Dev

Call a member function of other Class

From Dev

Passing a member function of a class to a parameter outside the class

From Dev

No matching function for call to Class Constructor

From Dev

No Matching Function Call to Base class

From Dev

No matching member function for call to child.value

From Dev

Passing std vector as reference: no matching function to call

From Dev

passing two dimension array to class member function

From Dev

passing a class member function: type issues

From Dev

c++ class passing member function issues

From Dev

Class design to call member function of another class

From Dev

Passing stack variables to pthread_cleanup_push

From Dev

Passing member function address to another class`s function

From Dev

Passing a class-member function to a global function as argument

From Dev

C++ Pointer to a member function of any class with matching function signatures

From Dev

Call function through pointer to class member

From Dev

How to call class member function in javascript

From Dev

How to call function with same name as class member

From Dev

call member function in another class c++

From Dev

How to call function from a member class?

From Dev

unable to call member function in class python

Related Related

  1. 1

    No matching function call when passing member function of a class to pthread_cleanup_push()

  2. 2

    No Matching Member Function to Call 'connect' - When Using 'this'

  3. 3

    Call member function when class type is not known

  4. 4

    no matching member function for call to 'insert'

  5. 5

    "is not a member of" and "no matching function for call to" errors

  6. 6

    No matching function for call to [class]

  7. 7

    No matching function for call to 'class'

  8. 8

    Calling sort() on a vector that's a member of a class "No matching function for call to swap()"

  9. 9

    "No matching member function for call to push" in Priority Queues C++

  10. 10

    Call a member function of other Class

  11. 11

    Passing a member function of a class to a parameter outside the class

  12. 12

    No matching function for call to Class Constructor

  13. 13

    No Matching Function Call to Base class

  14. 14

    No matching member function for call to child.value

  15. 15

    Passing std vector as reference: no matching function to call

  16. 16

    passing two dimension array to class member function

  17. 17

    passing a class member function: type issues

  18. 18

    c++ class passing member function issues

  19. 19

    Class design to call member function of another class

  20. 20

    Passing stack variables to pthread_cleanup_push

  21. 21

    Passing member function address to another class`s function

  22. 22

    Passing a class-member function to a global function as argument

  23. 23

    C++ Pointer to a member function of any class with matching function signatures

  24. 24

    Call function through pointer to class member

  25. 25

    How to call class member function in javascript

  26. 26

    How to call function with same name as class member

  27. 27

    call member function in another class c++

  28. 28

    How to call function from a member class?

  29. 29

    unable to call member function in class python

HotTag

Archive