search

Home  >  Q&A  >  body text

C++,非公有成员都包括什么?

protected+private还是只有private?

天蓬老师天蓬老师2803 days ago538

reply all(2)I'll reply

  • 大家讲道理

    大家讲道理2017-04-17 15:03:33

    protected and private. Constructors and destructors, as well as static member functions and friend member functions (rarely used) can be protected or even private.
    Private constructors do not allow external objects to be constructed directly, while classes can provide specialized factory methods or singleton methods to construct objects.

    reply
    0
  • 黄舟

    黄舟2017-04-17 15:03:33

    The members of the C++ class include these:

    1. 构造和析构(Public by default, not public, how to create and destroy it?)

    2. The methods and variables described by
    3. public are shared. (Can be called externally)

    4. The methods and variables described by protect are protected. (Not callable from outside)

    5. private Described methods and variables, private (not callable from outside)

    6. The methods and variables described by
    7. static do not belong to any object, but belong to the entire class. The calling method is 类名::方法|变量

    8. friend describes methods and variables, commonly used friend functions. In order to make member functions of other classes access the private members of the class.

    Basically these. I think the non-public properties of C++ should be except for public, that is, 3, 4, 5, 6.

    reply
    0
  • Cancelreply