Quote:Original post by Mawww
well i agree that in structures we usually don't have methods except for constructor and destructors
If you have to have a destructor then that implies (to me) that the struct is responsible for looking after some important data or resources etc. It would make sense to make the data private.
In C++, structs can do everything a class can do. However people often use structs to bunch data together but which doesn't have any functionality or responsibilities. Once you start getting them (responsibilities that is), people would usually use a class. This is a style and not a neccessity.
I often use structs for things like functors, which aren't passed around or don't have any important data, or in example code on gamedev, but it is simply because it means I have to finger type less and it makes the examples shorter (not littered with public, private etc). e.g.
struct RenderThing { RenderThing(Renderer& renderer) : m_renderer(renderer) { } void operator()(const Thing& thing) { thing.Render(m_renderer); } Renderer& m_renderer;};