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
structand aclassis that the latter’s default member accessibility isprivate, while the former’s ispublic.If only single inheritance is involved, the
class‘s address should be the same as thestruct‘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.