Structure vs class in C++

 The C++ class is an extension of the C language structure. Because the only difference between a structure and a class is that structure members have public access by default and class members have private access by default, you can use the keywords class or struct to define equivalent classes.


In C++, a structure works the same way as a class, except for just two small differences. The most important of them is hiding implementation details. A structure will by default not hide its implementation details from whoever uses it in code, while a class by default hides all its implementation details and will therefore by default prevent the programmer from accessing them. The following table summarizes all of the fundamental differences.


Class

Structure

Members of a class are private by default.Members of a structure are public by default. 
Member classes/structures of a class are private by default.Member classes/structures of a structure are public by default.
It is declared using the class keyword.It is declared using the struct keyword.
It is normally used for data abstraction and further inheritance.It is normally used for the grouping of data

Comments

Popular posts from this blog

Two Sum II - Input Array Is Sorted

Comparable Vs. Comparator in Java

Increasing Triplet Subsequence