Default inheritance access specifier

前端 未结 9 1707
北海茫月
北海茫月 2020-12-04 19:12

If I have for example two classes A and B, such that class B inherits A as follows:

class B: public A

9条回答
  •  萌比男神i
    2020-12-04 19:28

    If you use class to define your class, the default access specifier will be private. (I think it's wrong, too.) If you use struct, however, it will be public.

    And class definitions are declarations, I think. A statement is what translates into actual code (unless optimized away, anyway).
    However, a mildly exotic feature of C and C++ is that expressions are statements. That's why 3+4; is a syntactically legal statement in C++ (although many compilers will warn about it having no effect). While it is obviously nonsense in this case, in general expressions are evaluated for their side effects. (An obvious example is discarding a function's return value. You call the function not to obtain a result, but for its side effects.)

提交回复
热议问题