In C++, a structure is the same as a class except for a few differences. The most important of them is security. A Structure is not secure and cannot hide its implementation details from the end user while a class is secure and can hide its programming and designing details. Following are the points that expound on this difference:
1) Members of a class are private by default and members of a struct are public by default.
For example program 1 fails in compilation and program 2 works fine.
2) When deriving a struct from a class/struct, default access-specifier for a base class/struct is public. And when deriving a class, default access specifier is private.
For example program 3 fails in compilation and program 4 works fine.
Related Article: Difference between C structures and C++ structures
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Rated as one of the most sought after skills in the industry, own the basics of coding with our C++ STL Course and master the very concepts by intense problem-solving.
- Difference between Single Bus Structure and Double Bus Structure
- STL Priority Queue for Structure or Class
- Difference between Abstract Class and Concrete Class in Java
- How to convert a class to another class type in C++?
- Difference between Base class and Derived class in C++
- Difference between Structure and Union in C
- Fork CPP | Course Structure
- Difference between data type and data structure
- Trie Data Structure using smart pointer and OOP in C++
- Difference between Structure chart and Flow chart
- Difference between Web Content, Web Structure, and Web Usage Mining
- Array of Structures vs. Array within a Structure in C/C++
- Difference between Database and Data Structure
- Structure Sorting (By Multiple Rules) in C++
- C++ Stream Classes Structure
- What all is inherited from parent class in C++?
- Can a C++ class have an object of self type?
- Simulating final class in C++
- What happens when more restrictive access is given to a derived class method in C++?
- How to make a C++ class whose objects can only be dynamically allocated?
Improved By : roopkatha