C vs C + + structural differences _c language

Source: Internet
Author: User

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.

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.