Re: Copy constructor question
On Apr 20, 11:36 pm, "Victor Bazarov" <v.Abaza...@comAcast.net> wrote:
James Kanze wrote:
On Apr 20, 3:09 pm, "Victor Bazarov" <v.Abaza...@comAcast.net> wrote:
[...]
In addition to those comments, the two c-tors (the default and the
parameterized on 'int') should be made into one (the new default):
A(int i = 0) : myvalue(i) {}
Both solutions are possible. Which one you prefer is a question
of style and taste; there's certainly no "should" about it.
Why 'no "should"'? "Should" does not exclude "possible".
At least in the English I'm most familiar with (that of the
midwest USA), should is a polite form of the imperative. You
*should* adopt the style required by the coding guidelines where
you work. You *can* omit defining the copy constructor in such
cases if the coding guidelines (or other considerations) don't
require it.
As a general rule, in the absense of some specific guideline
otherwise, I will omit it in local classes used only within my
implementation, but provide it explicitly in "published"
classes; those on whose interface other classes, written by
other people, depend. But there are exceptions. In both
directions.
And I do not agree that minimizing the number of functions is
arbitrary. It's definitely _better_.
Except that you don't minimize the number of functions. There
are exactly the same number of functions in both cases.
And there is probably no need for the copy c-tor as it's implemented.
The one the compiler will generate is absolutely sufficient.
Still, most coding guidelines would require an explicit one, to
avoid making it inline.
How would you "avoid maing it inline" by keeping it in the class
definition?
Every coding guideline I've seen forbids defining functions in
the class definition.
We are talking about professional programming, aren't we?
Obviously, if it's just for your own personal satisfaction, you
do whatever gives you the most satisfaction.
--
James Kanze (Gabi Software) email: james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34