Topic: simple constructor : unify X(A) and X::operator=(A)
Author: "Kirk Odle" <kodle@ghg.net>
Date: 1998/02/11 Raw View
> in this newsgroup the rule is : "if it can't be done, correct the
>standard".
>
> for the success of C++ the rule should be : "if it can't be done more
>easily, correct the standard".
Ease of use is an important consideration. It is not the only
consideration, nor is it always the most important.
Correctness of use, correctness and coherence of a feature as implemented in
compilers, criticality of need,
relative difficulty of existing methods for achieving the same end.
Personally, I don't see the success of C++ as so seriously threatened that
the C++ community should
panic and add features to the language at the cost of compatibility with
existing code, making the language bigger,
introducing new subtleties and inefficiencies or making the language itself
less coherent. C++ is already successful.
Borland sold hundreds of thousands of C++ compilers before they even dreamed
of Delphi. Using that as the sole
basis for what amounts to an assertion that C++ is in some sort of decline
does nobody credit.
[ 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 ]
Author: Valentin Bonnard <bonnardv@pratique.fr>
Date: 1998/02/07 Raw View
Brad Daniels <brad.daniels@missioncritical.com> writes:
> Loic Tregan wrote in message <34D8AA17.14C3@cert.fr>...
> >X x( 5 ); calls X() then operator=(int)
Writing the ctor:
X::X (int i) { operator= (i); }
isn't _that_ difficult, is it ?
> Try:
>
> X x=5;
>
> You may be pleasantly surprised.
I fail to see how a message like:
cannot convert from int to X
is a pleasant surprise.
--
Valentin Bonnard mailto:bonnardv@pratique.fr
info about C++/a propos du C++: http://www.pratique.fr/~bonnardv/
[ 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 ]
Author: "Kirk Odle" <kodle@ghg.net>
Date: 1998/02/09 Raw View
How would a declaration specify that relationship? Are you suggesting that
the mere presence of a default constructor
would cause the compiler to invoke that constructor as a part of copy
construction? That would break a lot of existing
code. It would also introduce a runtime complexity that provides little
benefit in most cases. Furthermore, the current
language standard (and every language level since Stroustrup's first edition
C++ Programming Language book) allows:
class X {
X();
X( int a ) // data members invoke their default constructors.
{ operator =( a ); } // we're calling the assignment operator to
initialize X
X & operator =(int a);
};
Loic Tregan wrote in message <34D8AA17.14C3@cert.fr>...
>would the following extension be useful :
>
>class X {
> X();
> X(Z);
> operator=( int );
> operator=( string );
> operator=( Z );
>}
>
>
>X x( 5 ); calls X() then operator=(int)
>
>
>
>X x( "loic" ); calls X() then operator=( string )
>
>X x( Z ); calls X(Z)
>
>
>Most of the time X(T) do the same thing than X() then X::operator=(T),
>do you agree ?
>
>
>from a more general point of view, I think that C++ has to be enhanced
>with little patches like this one in order to be more easy for people (
>and please remind that each time JAVA is cited in a article, the author
>speaks about the simplicity of the language to justify - in part - the
>fact that JAVA is popular)
So, suggest something that simplifies the language without breaking existing
code or features. Your motivation is good, but there are several things in
your post that suggest your understanding of C++ has not developed to the
stage where criticizing the language or suggesting new features is
appropriate.
The key factor behind JAVA's popularity is its association with the
internet which is exploding into every facet of modern culture. The key
technical factor behind its success is that the language limits its
applicability to filling requirements that are simple in environments
that are defined to play to its strengths. That is, JAVA has a narrow
dynamic range and assumes a simple operational profile. As it is
applied to larger projects in settings that do not cater to its machine
model, it will be shown that JAVA is a lead bullet rather than a silver
one.
---
[ 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 ]
Author: Loic Tregan <Loic.Tregan@cert.fr>
Date: 1998/02/09 Raw View
Valentin Bonnard wrote:
>
> Brad Daniels <brad.daniels@missioncritical.com> writes:
>
> > Loic Tregan wrote in message <34D8AA17.14C3@cert.fr>...
>
> > >X x( 5 ); calls X() then operator=(int)
>
> Writing the ctor:
>
> X::X (int i) { operator= (i); }
>
> isn't _that_ difficult, is it ?
>
nothing is difficult, but what people want is a scripting language. We
have the proof everyday : success of Delphi over C++ Builder ( same tool
except for the language : pascal for delphi), success of Java, etc.
we have the chance with C++ to make a language both easy and coherent,
suitable from the engineer of higlhy technical components to the user of
these components.
in this newsgroup the rule is : "if it can't be done, correct the
standard".
for the success of C++ the rule should be : "if it can't be done more
easily, correct the standard".
---
[ 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 ]
Author: "Brad Daniels" <brad.daniels@missioncritical.com>
Date: 1998/02/10 Raw View
Valentin Bonnard wrote in message <34DCB5F3.2C2A@pratique.fr>...
>Brad Daniels <brad.daniels@missioncritical.com> writes:
>
>> Loic Tregan wrote in message <34D8AA17.14C3@cert.fr>...
>
>> >X x( 5 ); calls X() then operator=(int)
>
>Writing the ctor:
>
> X::X (int i) { operator= (i); }
>
>isn't _that_ difficult, is it ?
If believe the concern is the case where the default ctor does a lot of work
that you don't want to duplicate in the int ctor and can't duplicate in the
assignment operator. It would be nice to be able to say something like:
X::X(int i) : X() { operator=(i); }
Since it would generally be useful to use a different ctor to help implement
a ctor. I frequently add helper functions to classes where I have a number
of similar ctors, though I still have to duplicate member-initializaers.
>> Try:
>>
>> X x=5;
>>
>> You may be pleasantly surprised.
>
>I fail to see how a message like:
>
> cannot convert from int to X
>
>is a pleasant surprise.
Every compiler I have used has (perhaps incorrectly) done a default
construction followed by an assignment given the above syntax. If I'm
reading the standard correctly, they were supposed to construct a temporary
and copy it.
Of course, I may have been misreading the behavior I was getting, since it
was rarely the behavior I wanted anyway.
- Brad
--
----------------------------------------------------------------------------
Brad Daniels | Was mich nicht umbringt macht mich hungrig.
Mission Critical Software | - Otto Nietzche
Standard disclaimers apply | (Friedrich's corpulent brother)
---
[ 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 ]
Author: Loic Tregan <Loic.Tregan@cert.fr>
Date: 1998/02/05 Raw View
would the following extension be useful :
class X {
X();
X(Z);
operator=( int );
operator=( string );
operator=( Z );
}
X x( 5 ); calls X() then operator=(int)
X x( "loic" ); calls X() then operator=( string )
X x( Z ); calls X(Z)
Most of the time X(T) do the same thing than X() then X::operator=(T),
do you agree ?
from a more general point of view, I think that C++ has to be enhanced
with little patches like this one in order to be more easy for people (
and please remind that each time JAVA is cited in a article, the author
speaks about the simplicity of the language to justify - in part - the
fact that JAVA is popular)
---
[ 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: "Brad Daniels" <brad.daniels@missioncritical.com>
Date: 1998/02/06 Raw View
Loic Tregan wrote in message <34D8AA17.14C3@cert.fr>...
>would the following extension be useful :
It's in there....
>X x( 5 ); calls X() then operator=(int)
Try:
X x=5;
You may be pleasantly surprised.
- Brad
--
----------------------------------------------------------------------------
Brad Daniels | Was mich nicht umbringt macht mich hungrig.
Mission Critical Software | - Otto Nietzche
Standard disclaimers apply | (Friedrich's corpulent brother)
[ 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 ]