The disadvantage of a large initialization list?

My employer has a policy that we use initialization lists in the constructor because it is more efficient.

However, I am developing a class that has 45 data members that need to be initialized. In accordance with the policy, this should be done in the initialization list in the constructor.

Besides readability, what would be the disadvantage of a large initialization list?

+5
source share
4 answers

You can format the list of member initializers according to several physical source lines so that there is no problem with readability.

The big problem, obviously, is that you have classes with 45 data members. Nothing is going to make working with such classes easier.


AClass::AClass( type1 val1
              , type2 val2
              // ...
              , type45 val45 )
: mem1( val1 )
, mem2( val2 )
// ...
, mem45( val45 )
{
}

, , :

AClass::AClass( type1 val1
              , type2 val2
              // ...
              , type45 val45 )
{
    mem1 = val1;
    mem2 = val2;
     // ...
    mem45 = val45;
}
+8

, , , , , 45 . , , .

, "" . .

+8

, - . Wiki :

- God , .

, , god .

, " ?" ( ) " " , , , . "

" ? ( )" " none", , , ( ).

+3
source

Some optimizations will not work, I suspect that embedding such a constructor will not work.

In any case: 45 data members sound a lot. Can you group them in such aggregated objects?

-1
source

All Articles