What is the Difference Between Structure vs Class?
Overview
This document summarizes about difference between structure and class in cpp.
Introduction
In Cpp, structure, and class are very similar syntax. Basically, two syntaxes play a role that defines another data type including variable and function(method). In addition, Cpp allows to include functions in the structure. So, Cpp's structure looks very similar to class.
In this document will explain what is difference between structure and class.
Difference Between Structure and Class
The decisive difference is in OOP(Object-Oriented-Programming). Cpp's class is syntax to implement OOP. For example, class syntax members's default access modifier is private. This supports Encapsulation, OOP's one of the features.
Below is a summary table about the difference.
| Class | Structure | |
|---|---|---|
| Purpose | For support OOP. | For group variable and function. |
| Access Modifier | Members of a class are private by default. | Members of a structure are public by default. |
| Declare | It is declared using the class keyword. | It is declared using the struct keyword. |
| Use | It is normally used for data abstraction and inheritance. | It is normally used for the grouping of different datatypes. |
Final Thoughts
Java, the object-oriented language I first learned, did not have structure syntax, so I could not study these differences. However, it was good to take this opportunity to see the difference between classes and structures.