Saturday, 15 March 2014

c++ - avoid declaring same data types in different structures -



c++ - avoid declaring same data types in different structures -

i have 2 -3 structures declared in code , these structures have mutual info type. in our company strict policy not duplicate code . wondering there way can declare these mutual info type in function , utilize function when declare structure.

example

struct_1 { ... united nations mutual stuff // below mutual declaration .. how declare below info type in function , // phone call here declare info type unsigned char char_1; unsigned int int_1; std::vector< small_structure> small_struct; } struct_2 { ... united nations mutual stuff unsigned char char_1; unsigned int int_1; std::vector< small_structure> small_struct; } struct_3 { ... united nations mutual stuff unsigned char char_1; unsigned int int_1; std::vector< small_structure> small_struct; }

why not create mutual struct then?

struct mutual { unsigned char char_1; unsigned int int_1; std::vector< small_structure> small_struct; } struct struct_3 { ... united nations mutual stuff struct mutual commonstuff; }

or if utilize c++, inherit mutual struct:

struct struct_3 : mutual { ... united nations mutual stuff }

but prefer composition on inheritance when possible.

c++ c

No comments:

Post a Comment