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.
© 2024 OneMinuteCode. All rights reserved.