Quick question:
Someone told me that it's not customary to use structs in c++,
is this true? :confused:
Printable View
Quick question:
Someone told me that it's not customary to use structs in c++,
is this true? :confused:
C++ structs and classes have no difference except the visibility option....in struct default visibility mode is public whereas in classes its private....
so your saying that there is no reason to use structs in c++?
There probably isn't much need for you to use structs while writing new programs, but a lot of libraries / API's use them (win32 for example), so you will still use them at some point.
Use whatevr you feel likeQuote:
Originally Posted by owi_just
I tend to use struct out of habit when I know I wont need any member functions.
Technically, there is no reason to use classes instead of structs in C++ code. They are the same thing, apart from default access specifiers.
structs are used to implement PoD (Plain old Data) types (which, broadly, means a struct type that would be understood by a C compiler: no user supplied constructors, destructors, member functions, private or protected attributes,...). PoD allow data structures to be passed to functions that are written in C.