jeudi 13 décembre 2018

static_cast to a struct type to access all of its member variable

I have a structure like below:

struct Param
{
    Param(const void* a, const std::vector<int>& b) : c(a), d(b) {}
    const void* c;  
    const std::vector<int> d; 
};

Now after creating a new instance of Param struct I store a class instance 'this' pointer in the member variable c. Later in a C Api (within C++ code) I need to refer back to the class pointer to invoke a method:

static_cast<ClassA*>(static_cast<Param*>(var->addr)->c)->ClassAMethod()

But the compiler states invalid expression type conversion. How can I refer to both Param structure variables in C Apis if the address of Param instance is stored in 'addr' variable?

Aucun commentaire:

Enregistrer un commentaire