Topic: Is a copy-constructor declaration ill-formed?
Author: Gregory Bond <gnb@bby.com.au>
Date: 1996/05/02 Raw View
In article <orbuk9otv5.fsf@pinheiros.dcc.unicamp.br> oliva@dcc.unicamp.br (Alexandre Oliva) writes:
3 A declaration of a constructor for a class X is ill-formed if its
first parameter is of type (optionally cv-qualified) X and either
there are no other parameters or else all other parameters have
default arguments.
What this is saying is that a putative copy constructor cannot take
its argument by VALUE, only by REFERENCE. Why? Consider how the
compiler passes objects by value: using the copy contructor! Infinite
recursion immediatley follows.
Greg.
--
Gregory Bond <gnb@bby.com.au> Burdett Buckeridge & Young Ltd Melbourne Australia
``Efforts to maintain the "purity" of a language only succeed in establishing an
elite class of people who know the shibboleths. Ordinary folks know better,
even if they don't know what "shibboleth" means.'' - Larry Wall
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: johnb@pivotal-dm.ccmail.compuserve.com (John Bain)
Date: 1996/05/03 Raw View
oliva@dcc.unicamp.br (Alexandre Oliva) wrote:
>The Jan'96 DWP states:
>
> 12.8 Copying class objects [class.copy]
>
>2 A constructor for class X is a copy constructor if its first parameter
> is of type X&, const X&, volatile X& or const volatile X&, and either
> there are no other parameters or else all other parameters have
> default arguments (_dcl.fct.default_). [ examples removed ]
>
>3 A declaration of a constructor for a class X is ill-formed if its
> first parameter is of type (optionally cv-qualified) X and either
> there are no other parameters or else all other parameters have
> default arguments.
>
>Hence, any declaration of a copy-constructor is ill-formed! :-)
>
>Is this a typo? What was paragraph 3 supposed to mean?
Read it again: paragraph 2 defines copy constructors for class X as
taking (cv) references to X, while the constructors paragraph 3 is
prohibiting involve passing values of type X.
I.e.
class X
{
public:
X(X&);
};
is OK, but
class X
{
public:
X(X);
};
is ill-formed.
Cheers,
John
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: oliva@dcc.unicamp.br (Alexandre Oliva)
Date: 1996/05/01 Raw View
The Jan'96 DWP states:
12.8 Copying class objects [class.copy]
2 A constructor for class X is a copy constructor if its first parameter
is of type X&, const X&, volatile X& or const volatile X&, and either
there are no other parameters or else all other parameters have
default arguments (_dcl.fct.default_). [ examples removed ]
3 A declaration of a constructor for a class X is ill-formed if its
first parameter is of type (optionally cv-qualified) X and either
there are no other parameters or else all other parameters have
default arguments.
Hence, any declaration of a copy-constructor is ill-formed! :-)
Is this a typo? What was paragraph 3 supposed to mean?
--
Alexandre Oliva
oliva@dcc.unicamp.br
Universidade Estadual de Campinas, S~ao Paulo, Brasil
---
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: kuehl@uzwil.informatik.uni-konstanz.de (Dietmar Kuehl)
Date: 1996/05/01 Raw View
Hi,
Alexandre Oliva (oliva@dcc.unicamp.br) wrote:
: The Jan'96 DWP states:
: 12.8 Copying class objects [class.copy]
: 2 A constructor for class X is a copy constructor if its first parameter
: is of type X&, const X&, volatile X& or const volatile X&, and either
: there are no other parameters or else all other parameters have
: default arguments (_dcl.fct.default_). [ examples removed ]
:
: 3 A declaration of a constructor for a class X is ill-formed if its
: first parameter is of type (optionally cv-qualified) X and either
: there are no other parameters or else all other parameters have
: default arguments.
: Hence, any declaration of a copy-constructor is ill-formed! :-)
No, the paragraphs do not contradict each other.
: Is this a typo? What was paragraph 3 supposed to mean?
Paragraph 2 says that a copy-ctor takes a cv-qualified REFERENCE to
'X'. I.e. the following four declarations are the ONLY declarations
valid for a copy-ctor for 'X' if no additional arguments with default
arguments are used:
X(X&);
X(X const &);
X(X volatile &);
X(X const volatile &);
The third paragraph says, that you cannot declare a constructor of 'X'
which takes an cv-qualified 'X' as first argument if it is either the
only argument or only arguments with default values are following. I.e.
the following declarations are all ill-formed:
X(X);
X(X const);
X(X volatile);
X(X const volatile);
Hence, there are some ill-formed declarations of a copy-ctor (e.g. the
latter four) and some well-formed declarations (e.g. the first four).
--
dietmar.kuehl@uni-konstanz.de
http://www.informatik.uni-konstanz.de/~kuehl/
I am a realistic optimist - that's why I appear to be slightly pessimistic
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]