F
Fokko Beekhof
Hello,
If a variable is declared and initialized, that can be done with an
assignment:
Foo bar = otherFoo;
or with a constructor:
Foo bar((otherFoo));
Which one is preferable ? I would guess by "constructor", because
otherwise the object would first be constructed, and then be copied
over, which is more work than constructing it after a given object in
the first place.
I guess that for basic type (int, double, etc. ) there is not much
difference, but for classes with a non-trivial copy-constructor and
assignment operator, it might make a difference.
Is that reasoning correct ?
Thanks in advance,
FPB
If a variable is declared and initialized, that can be done with an
assignment:
Foo bar = otherFoo;
or with a constructor:
Foo bar((otherFoo));
Which one is preferable ? I would guess by "constructor", because
otherwise the object would first be constructed, and then be copied
over, which is more work than constructing it after a given object in
the first place.
I guess that for basic type (int, double, etc. ) there is not much
difference, but for classes with a non-trivial copy-constructor and
assignment operator, it might make a difference.
Is that reasoning correct ?
Thanks in advance,
FPB