Ich versuche, Zeiger auf eine void *
Funktion innerhalb der Hauptmethode aufrufen und der Compiler sagt assigning to 'funcptr<g>' from incompatible type 'void *(void *)
. hello
Funktion ist eigentlich ein Argument zu pthread_create
Funktion. Deshalb ist es void *
Funktion. Wie kann ich einen Funktionszeiger auf eine void *
Funktion erstellen?Zeiger auf eine void * -Funktion C++
#include <iostream>
#include <pthread.h>
using namespace std;
template<typename T>
using funcptr = void (*T::*)(void *); // I think it is wrong here.
class m {
public:
template <typename T>
struct my_struct {
funcptr<T> ptr;
};
};
class g {
public:
static void *hello(void *);
};
int main() {
struct m::my_struct<g> h;
h.ptr = g::hello; // Error here
return 0;
}
Ich bin nicht sicher, was die neue Art und Weise, dies zu tun, aber ich immer nur tat 'typedef void (* funcptr) (void *);' –
Seit 'hallo 'ist eine statische Funktion, brauchen Sie nicht' funcptr' auf Vorlage: 'mit funcptr = void * (*) (void *);' Für Klasse m: 'Klasse m { public: \t struct my_struct { \t \t funcptr ptr; \t}; }; ' In Haupt: ' struct m :: my_struct h; h.ptr = & g :: hallo; // Nimm die Adresse von hallo' – kjpus
Verwende std :: thread, verwende keine OS-Threads direkt. –