C + + static member functions, static member variables, operator overloading

Source: Internet
Author: User

When a function is not part of a specific instance and belongs to the entire class, then this function is best written as a static member function, so that it can be called directly with the class name

Class::func ()

For general member functions when using obj. Func () When the function is called, the compiler compiles it to the style of typeof (obj):: Func (), so a static member function cannot be called

Both the friend function and the static member function do not belong to the class and are not passed in when invoked, so you cannot use the

Only allow this class of objects to share data, let member variables be declared static, static data member initialization to be placed outside, Class::name = value, because it belongs to the class, so the allocation of space is defined outside the time of allocation, not when the object definition is allocated

C + + is optimized for anonymous objects and is optimized to create new objects directly without having to establish an intermediate object. The anonymous object compiler can be released as early as possible, and a good compiler can optimize

General single-Mesh: Fanhuizhi operator+ () {}

Special point with dummy Fanhuizhi operator++ (int/* with int for post Plus, no int for front Plus/)

The overload of the type conversion operator Fanhuizhi operator double () {}, because the return value type is the same as the function name, so C + + can allow non-write return value types, plus boolalpha can see the bool type converted to true false, Come on, add Noboolalpha.

C + + static member functions, static member variables, operator overloading

Related Article

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.