Basic Learning notes like C + +

Source: Internet
Author: User

Data members declared in 1.private can only be accessed by member functions in public, that is, data hiding, which is encapsulated.
2. Each class has a constructor that initializes the class object when it is created, and the constructor must be guaranteed to have the same name as the class to distinguish the other
member functions, generally declared public
3. Every time an object is created, C + + requires a constructor to be called once, which guarantees that the program is initialized correctly. In any absence of an explicit
In the class that contains the constructor, the compiler provides a default constructor to initialize.
Note: When an object is created with an argument constructor defined, it cannot be created directly like the previous Gradebook Mygradebook.
Otherwise you will get an error because you have defined a constructor, so you have to create it in the form of a constructor, such as Gradebook Mygradebook ("abc");
If the constructor does not have an argument, it is defined as gradebook mygradebook; Note that there is no parentheses here.
4. The reusability of independent files, that is, we write classes may be used by other different programs, so for convenience, we can put the class and main function
Separated, where the class retains the name "GradeBook.h", which is what. h, and then if the main function is going to call it, you can start with
#include "GradeBook.h" to invoke. It is important to note that both are placed in the same directory.
5. Declaration of class, implementation and separation of main function: declaration is saved as. h file, the same name is saved as CPP, the main function call directly
Call "GradeBook.h". Note that it is implemented with Gradebook::
The validity of the 6.set function can guarantee the validity of the incoming parameters, such as Setcoursename () if the name is guaranteed to be within 25 characters,
Then it can be handled in the SET function.

Basic Learning notes like C + +

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.