in C++, can I derive a class from a struct

后端 未结 3 2023
一整个雨季
一整个雨季 2020-12-09 15:36

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

3条回答
  •  星月不相逢
    2020-12-09 15:52

    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.

提交回复
热议问题