+ 4

Struct vs CLasses....When to use one over the other?

I am new to oops in cpp and seen structs before ...Both the data types seems kind of similar ....SO why would we need to use one over the other...?

16th Feb 2018, 7:31 PM
3D CrackerJack
3D CrackerJack - avatar
2 Answers
+ 5
There are no major difference except for one... In a class the members are private by default...(i.e they can't be used outside the class) In a struct the members arepublic by default (i.e you can use them outside the struct too) And use this for reference as this ? has been asked way too many times :) https://stackoverflow.com/questions/54585/when-should-you-use-a-class-vs-a-struct-in-c
16th Feb 2018, 7:33 PM
Cyberspace Cyborg
Cyberspace Cyborg - avatar
0
I would say that classes are but tricky so you can probably use the structures as they have all the members public by default and in a class all the members are private unless we declare them to be public
17th Feb 2018, 6:05 PM
Rajanish Sharma
Rajanish Sharma - avatar