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}