C struct member pointer to C++ class instance

Is it possible to have a C struct member pointer point to a instance of a class?

C header file myCstruct.h
1
2
3
4
struct
{
    myClass* m_instance;
} myCstruct;


C++ file main.cpp
1
2
3
4
5
6
7
8
extern "C" {
    #include "mCstruct.h"
}

void GetClassInstance( myCstruct* ptr )
{
    ptr->m_instance = new myClass();
}
I don't think so.

C++ can work with C, but not the other way around.

You could use a void pointer and then just cast it when you needed to, but blech.

I'm not really an expert on C, though, so maybe someone else can correct me on this.
DIsch is correct. The proper way to do this is through a void* on the C side. To do anything with that void* on the C++ side you will need to use a dynamic_cast.
Topic archived. No new replies allowed.