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

ruby - When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying -

php - PHPDoc: @return void necessary? -

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