Polymorphism, friend and static member basic knowledge summary

Source: Internet
Author: User

1.

The function is finished when the late binding runs.

Class Point

{

Public

Virtual double area () {}

...

}

Class Circle:public Point

{

Public

Double area () {}//is still a virtual function and cannot be written when redefined

}

Double CalcArea (Point &ref) {}

The program runs a member function that invokes the object based on the object referenced by ref.

A virtual function cannot be a friend, a static function, not an inline, constructor. It can be a destructor.

2.

Pure virtual function:

virtual function type function name () = 0;

Each derived class then re-defines these virtual functions as required.

Abstract classes (with at least one pure virtual function) can only be used as the base class for other classes, cannot create objects, and abstract classes may define ordinary functions.

3.

Friend £ º

Class Date;

Class Clock;

Class Clock

{

Public

friend void Display (Clock &);

}

Class Date

{

Public

friend void Clock::D isplay (Date &);

}

You can also friend class:

Friend class name;

4.

Static Members:

static int sum;

static int Display ();

It is shared for all objects of the class, opening up space outside of all objects, even if the object is not defined, and also allocates space (at compile time).

Static member initialization:

Data type class Name:: static data member name = initial value;

Can no longer be initialized in a class declaration.

Static member functions cannot access non-static members of this class by default, without the this pointer.

Access method:

Class Student;

Student S1;

Student::sum;

or s1.sum;

Polymorphism, friend and static member basic knowledge summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.