Which is better, class or structure in C++?

Asked 2 years ago, Updated 2 years ago, 96 views

When do you write structure and when do you write class?

class oop c++ struct ooad

2022-09-22 22:29

1 Answers

Which is better, class or structure in C++?

When do you write structure and when do you write class?

C can only write structure and C++ can write both strut and class. And Cstructure and C++structure are not the same, and think of C++structure here as C++structure.

Both structure and class can have public, private members, inherit, and have member functions.

The difference between the two is

When structure requires POD structure that does not require functions such as class (inheritance, encapsulation, etc.), class is used to manage data integrally by using private member variables/member functions I recommend using it.


2022-09-22 22:29

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.