From 1499169176185502166
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,5e69b3c02624e7d0
X-Google-Attributes: gidf78e5,public
From: Aldo Aleardi <aldo.a@interplanet.it>
Subject: Re: A C++ asymmetry
Date: 1999/09/15
Message-ID: <ZNbeN1BJDUKmxUBwd59jNbHc1yUa@4ax.com>#1/1
X-Deja-AN: 525402506
Content-Transfer-Encoding: 7bit
Approved: Fergus Henderson <fjh@cs.mu.oz.au>
References: <yfHaNyPjoGWxa6bbbTdKITIXiWzP@4ax.com> <IsmXneAGW$23Ewm3@robinton.demon.co.uk>
X-Original-Date: Wed, 15 Sep 1999 01:16:12 +0200
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: news@news.unimelb.edu.au
X-Trace: ariel.ucs.unimelb.edu.au 937400794 23700 128.250.37.153 (15 Sep 1999 13:06:34 GMT)
Organization: IUnet
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUAN9+ZzeEDnX0m9pzZAQEB/QF/Xs6WYEb33ajsjwJs2v0/vfCrsRh1qEQ6 xLaqyPAWHYZF/mMC+qvnUmQRTJGJ70qq =vTtM
Mime-Version: 1.0
NNTP-Posting-Date: 15 Sep 1999 13:06:34 GMT
Newsgroups: comp.std.c++

On 13 Sep 1999 16:17:07 GMT, Francis Glassborow
<francis@robinton.demon.co.uk> wrote:

[sorry for snipping]
>However it seems difficult to imagine a case where a user written copy
>ctor was needed but a compiler generated default ctor would do the right
>thing.  Would you like to provide a counter example?  Without one it
>seems that the standard is entirely correct in this asymmetry.
>  

Maybe my mathematical background raises its head from time to time,
so allow me to put it this way:

(ISO C++ compiler speaks)
"Hey user, you have defined no copy constructor for your class
so, whether or not you have defined some constructors, I'm willing
to generate a default copy constructor for you! You know well
the way it will behave, don't 'you? Come on then, if it satisfies
your needs, use it; otherwise handle your object's copy construction
by yourself."

This is right, isn't it? It's up to the user to choose.

Now, if in this correct sentence I replace the "copy constr.."
occurences with "constr.." and viceversa, I get a wrong sentence
according to the standard. And that seems a bit illogical to me.

Back to the point!

class MyClass {
public:
//
//
private:
//
//
	MyClass( const MyClass& ); // not implemented
};

Let's suppose for a moment that for this particular class
the most appropriate constructor, say for efficiency reasons,
be the implicitly default generated constructor: what to do
in such situation?
A very simple workaround would be to add a line of code
to MyClass:

class MyClass {
public:
  MyClass(){}
  //...
};

but a little later
...
MyClass mca[1000];
...
Yes I know, I have implicitly defined MyClass::MyClass() inline,
but I have no guarantee that it, no matter how simple it is,
will be actually inlined so I have to take into account the
legendary Murphy's Law.  There will surely be 1000 "calls" of
MyClass::MyClass()  with the subsequent runtime overhead.

My conclusions (probably wrong)? This asymmetry should be
eliminated by making the sentence above correct or not with
or without the replacements I have pointed out. 


>Francis Glassborow      Journal Editor, Association of C & C++ Users
>64 Southfield Rd
>Oxford OX4 1PA          +44(0)1865 246490

Best Regards, Aldo
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]



