data structures - Should I use structs in C++? -


the difference between struct , class small in c++, struct members per default public , class members per default private.

however, still use structs whenever need pure data structures, instance:

struct rectangle {     int width;     int height; }; 

i find convenient work with:

rectangle r; r.width = 20; r.height = 10; 

however, data structures procedural programming, , i'm doing object oriented programming. bad idea introduce concept oo?

no. if makes sense use struct somewhere, why complicate things using else isn't meant fit purpose ?

in projects, tend use struct simple "structures" need hold trivial data.

if data structure needs have "smartness" , hidden fields/methods, becomes class.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -