(Improve code) note the details when writing code 1~10 bar

Source: Internet
Author: User

This article will continue to be updated with experience gained in book records, online articles or work practices.

It can effectively improve the efficiency of your code, reduce code redundancy, and improve the code's objectivity (others view the code).

1. A member variable is initialized at the time of the constructor, as much as possible with initialization.

Class CTest
	{
	private://Initializes a member function at construction time, reducing the value of the assignment step
        ctest (): M_data (NULL) {}
        ~ctest ();
	Private:
		int m_data;	Data
        }

Initialize a member variable only once when the target is constructed

Class CTest
	{
        ctest () {m_data=null;}
        ~ctest ();
	Private:
		int m_data;	Data
        }

Initialize the member variable by default at Target construction, and then assign null to m_data for two numeric operations



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.