Possible Duplicates:
When should you use a class vs a struct in C++?
What are the differences between struct and class in C++
struct X{
};
class X{
};
in C++, Same task can be done by class
as well as struct
. My question is where should I use class
and where struct
?
The differences between a struct and class in C++ are:
But basically anywhere you use a struct you could use a class, and vice versa, so it's really up to you what to use. Conventionally, when you have methods, it is more common to use a class, and when you only have data, structs are more commonly used.
I would say that if you want all the data members to be public, and you have no methods, then use a struct. Otherwise use a class. But that's just personal preference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With