[C++复习]04| classes and objects(2)

[note 1]

The type and scope of each static member variable must be defined outside the class definition.
[form]:

  • type class-name::static-member-name
  • type class-name::static-member-name=initial-value

[note 2]

Static member functions can have only other static members declared in the same class.

A static class can be called using the class name (instead of its object name) as follows

  • class-name::function-name

[note 3]

  • A constant object can call only const member functions.
  • A constant object can call only const member functions.
    Whenver const objects try to invoke non-const member functions, the compiler generates errors.

[note 4]

Define a pointer to the member
int A:: * ip= &A::m
The ip pointer acts like a class member in that it must be invoked with a class object.

[note 5]

Friend function can’t be invoked by using objects, while it can be invoked like a normal function without the help of any objects.
Friend function can be declared either in the public or the private part of a class without affecting its meaning.
Member function of one class can be friend functions of another class.

发布了51 篇原创文章 · 获赞 5 · 访问量 4208

猜你喜欢

转载自blog.csdn.net/qq_43519498/article/details/92719503