Class and Class in C ++

Source: Internet
Author: User

Class and Class in C ++

As a key word of C ++, class has multiple functions:

1. Define "class ". Classes in C ++ are the most basic attributes. It is an abstraction of members with the same attributes. Members in a class have all the attributes of the class.

The keyword defining a class in C ++ is class:

1 class child 2 {3 public: // specifies the external visibility and accessibility. 4 child (): age (10), sName ("LiMing "){}; // constructor. During class instantiation, initialization of some variables can be provided 5 ~ Child (); // The Memory reclaim function is provided when the class object is deleted. 6 private: 7 unsigned int age; 8 9 string sName; 10 };

2. When defining a template function, it is used to specify the type that the function can receive: The following two definitions are the same:

1 template <class T> 2 T abse (T x) 3 {4 return x> 0? X:-x; 5 6} 7 8 template <typename T> 9 T abse (T x) 10 {11 return x> 0? X:-x; 12 13}


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: 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.