The structure in C is different from the structure in C + +: The structure in C can only customize the data type, the structure body does not allow functions, and C + + structure can join member functions.
Similarities and differences of structures and classes in C + +:
one, the same: the structure can contain functions, you can also define public, private, protected data members, after defining the structure body, you can use the structure name to create the object. But the structure in C is not allowed to have functions, that is to say, in C + +, the structure can have member variables, can have member functions, can inherit from other classes, can also be inherited by other classes, can have virtual functions.
difference: The member in the definition of a struct is public by default, and the member in the class definition by default is private. A non-static member function in a class has the this pointer, (and struct is not wrong, has been misled, the struct member function has the same as the this pointer), the class's keyword class can be used as the template template keyword that template <class t> class a{}; and struct not to be.
In fact, the structure in C only involves the data structure, but not the algorithm, that is, in c the data structure and algorithm is separate, and in C + + or a struct can contain functions (this function in C + + we usually called member functions), C + + The structure and class embody the combination of data structure and algorithm.