struct as a base class - C/C++ interoperability
c, c++, class, oop, struct
Solution
If I pass `Base_Struct*` to a C file, will the C code be able to use the `Base_Struct` completely?
If it's a standard-layout class, and the C compiler uses the same ABI for such classes as the C++ compiler, then it can access all the data members. Obviously, it couldn't access any member functions or static members, since such things don't exist in C and would have to be left out of any C-compatible definition of the structure.
What about the derived class?
You couldn't define that class in a C program, so it couldn't do anything interesting with the pointer.
Problem
I recall I saw somewhere some code which used to have a struct as a base class, and a C++ class as a derived class ``` struct Base_Struct { } class Derived : Base_Struct { ... } ``` And the point is that a pointer to Base_Struct* was passed from the C++ files to some C files which then managed to use some function pointers in Base_Struct. My question is: if I pass Base_Struct* to a C file, will the C code be able to use the Base_Struct completely? What about the derived class?