[Halld-offline] [Fwd: CLEO coding standard]

Matthew Shepherd mashephe at indiana.edu
Thu Sep 17 21:24:31 EDT 2009


Hi all,

I take back my comment -- Richard helped set me straight on the C++  
standard!  I agree with his remarks.  His change is easy to implement  
and helps avoid unnecessary confusion.

-Matt

On Sep 17, 2009, at 3:49 PM, Matthew Shepherd wrote:

>
> Hi Richard,
>
> I think every class should *declare* a default constructor.  As you
> point out, for some classes it is not appropriate to have a default
> constructor.  In this case the default constructor should be declared
> private (as the rule states).  If you don't declare a default
> constructor then the compiler can auto-generate one, which can lead to
> problems for certain classes.
>
> The issue here may be correctly interpreting the word "declare" which
> means "explicitly written in the header file" (to prevent auto-
> generation).  It does not imply the constructor is defined or public.
>
> -Matt
>
>
> On Sep 17, 2009, at 3:06 PM, Richard Jones wrote:
>
>> Response to proposed coding standard:
>> 	• All classes should declare a copy constructor, an assignment
>> operator from its own type, a default constructor and a destructor.
>> Any that are not used should be declared private and not defined.
>> Comment: I suggest a change from "a default constructor and a
>> destructor" to "at least one constructor and destructor".  It is not
>> always appropriate to have a default constructor, and default
>> constructors are only automatically generated if there are no non-
>> trivial constructors defined.  This rule does not state whether they
>> must be public or not.  There are cases such as friend factory
>> classes where having no public constructors actually makes the most
>> sense.  But regardless, there should not be a rule that says every
>> class must have a default constructor.  Even though it is possible,
>> it suggest semantics to the user of the class that may actually not
>> make any sense.
>> 	• All classes which might possibly be used as base classes must
>> define a virtual destructor.
>> I think modern compilers flag this as an error.  If so, we don't
>> need a rule about it.
>>
>> -Richard Jones
>>
>>
>>
>>
>> Mark M. Ito wrote:
>>>
>>> Folks,
>>>
>>> Matt Shepherd sent this to me last week. I think it serves as an
>>> example
>>> of what we might want to adopt for a coding standard and can serve
>>> as a
>>> starting point for a discussion. Read it over and send out your
>>> comments
>>> to the list or to me if so moved. We will discuss the idea of
>>> standards
>>> at a future Offline meeting, of course.
>>>
>>>  -- Mark
>>>
>>>
>>>
>>
>> _______________________________________________
>> Halld-offline mailing list
>> Halld-offline at jlab.org
>> https://mailman.jlab.org/mailman/listinfo/halld-offline
>
>
> _______________________________________________
> Halld-offline mailing list
> Halld-offline at jlab.org
> https://mailman.jlab.org/mailman/listinfo/halld-offline





More information about the Halld-offline mailing list