Is it possible to have a class inheriting from a struct?
More specifically, how can I wrap a C struct with a class, so that I can pass class pointers to methods that requires struct ptr and cast back when I receive the pointer in e.g. callbacks?
(Or even more specifically, the address of the class should be same same address as the struct...)
You just derive from the C struct. In C++, the only difference between a struct and a class is that the latter's default member accessibility is private, while the former's is public.
If only single inheritance is involved, the class's address should be the same as the struct's which acts as a base class. If the inheritance only serves the implementation (that is, there is no Is-A relationship between the two), consider using private inheritance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With