The question says it all really. Am I allowed derive a class from a struct, or should I create a class that embeds my struct and defines copy constructors and an = operator to move between the two?
Struct cannot be a base class. So, Struct types cannot abstract and are always implicitly sealed. Abstract and sealed modifiers are not allowed and struct member cannot be protected or protected internals.
Structs and inheritanceIt is not possible to inherit from a struct and a struct can't derive from any class. Similar to other types in . NET, struct is also derived from the class System.
The only difference between a struct and class in C++ is the default accessibility of member variables and methods. In a struct they are public; in a class they are private.
Yes. The inheritance is public by default.
In C++ struct
is (almost) synonymous to a class
(except of different default access level), so yes, you can.
struct A { // fields are public by default }; class B: public A { // fields are private by default };
I'm not familiar with MFC, but it looks like an attempt to maintain both C and C++ APIs.
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