Topic: Suggestion: Constructors without implicit type conversion
Author: bs@alice.att.com (Bjarne Stroustrup)
Date: 25 May 94 17:57:50 GMT Raw View
peters@phibm60c.Physik.Uni-Augsburg.DE (Peter Schmitteckert @ UniAugsburg) writes
> I want to repeat a suggestion, I did in january, as I'm more experienced
> in C++ now: "Constructors without implicit type conversion".
...
> So I suggest a constructor !X
> (similiar to ~X, "!" stands for no implicit type conversion)
> class X
> { ....
> public : !X(Type y) { ... };
> }
> to be a constructor without allowing implicit type conversions.
The problem has been noted and a roughly equivalent proposal has been
made and will be discussed in July.
- Bjarne
Author: maxtal@physics.su.OZ.AU (John Max Skaller)
Date: Sat, 28 May 1994 14:10:24 GMT Raw View
From: h.b.furuseth@usit.uio.no (Hallvard B Furuseth)
>> class X {
>> constructor X(int);
>> constructor(int);
>> };
>>
>> These things do not do implicit conversions. Will that do?
>> (Note this is a proposal not an accepted resolution)
>
>Great, I've wanted unnamed constructors and destructors. Is
> ~constructur();
>included too?
Its named "destructor".
--
JOHN (MAX) SKALLER, INTERNET:maxtal@suphys.physics.su.oz.au
Maxtal Pty Ltd, CSERVE:10236.1703
6 MacKay St ASHFIELD, Mem: SA IT/9/22,SC22/WG21
NSW 2131, AUSTRALIA
Author: maxtal@physics.su.OZ.AU (John Max Skaller)
Date: Tue, 24 May 1994 22:26:28 GMT Raw View
In article <CqBKv3.M9H@Yuri.CC.Uni-Augsburg.DE> peters@phibm60c.Physik.Uni-Augsburg.DE (Peter Schmitteckert) writes:
>Hallole ,
>
>I want to repeat a suggestion, I did in january, as I'm more experienced
>in C++ now: "Constructors without implicit type conversion".
>
Nathan Myers has a paper on it. The syntax is:
class X {
constructor X(int);
constructor(int);
};
These things do not do implicit conversions. Will that do?
(Note this is a proposal not an accepted resolution)
--
JOHN (MAX) SKALLER, INTERNET:maxtal@suphys.physics.su.oz.au
Maxtal Pty Ltd, CSERVE:10236.1703
6 MacKay St ASHFIELD, Mem: SA IT/9/22,SC22/WG21
NSW 2131, AUSTRALIA
Author: h.b.furuseth@usit.uio.no (Hallvard B Furuseth)
Date: 25 May 1994 10:57:52 GMT Raw View
(Oops, wrong the first time. Next try...)
In article <CqBvo4.5v6@ucc.su.OZ.AU> maxtal@physics.su.OZ.AU (John Max Skaller) writes:
> Nathan Myers has a paper on it. The syntax is:
>
> class X {
> constructor X(int);
> constructor(int);
> };
>
> These things do not do implicit conversions. Will that do?
> (Note this is a proposal not an accepted resolution)
Great, I've wanted unnamed constructors and destructors. Is
~constructur();
included too?
--
Hallvard
Author: peters@phibm60c.Physik.Uni-Augsburg.DE (Peter Schmitteckert)
Date: Thu, 26 May 1994 14:21:11 GMT Raw View
JOHN (MAX) SKALLER wrote
> Nathan Myers has a paper on it. The syntax is:
>
> class X {
> constructor X(int);
> constructor(int);
> };
>
> These things do not do implicit conversions. Will that do?
> (Note this is a proposal not an accepted resolution)
If these are constructors which do no impicit conversions, then they're just
what I want.
Could someone add a little more information on this proposal, please.
Thanks in advance
Peter
------------------------------------------------------------
Peter Schmitteckert * Lehrstuhl fuer Theoret. Physik 2
Institut fuer Physik * D 86135 Uni Augsburg
e-mail: Peter.Schmitteckert@Physik.Uni-Augsburg.de
Phone: +49-821-5977-246
Fax: +49-821-5977-262
Author: peters@phibm60c.Physik.Uni-Augsburg.DE (Peter Schmitteckert)
Date: Tue, 24 May 1994 18:33:03 GMT Raw View
Hallole ,
I want to repeat a suggestion, I did in january, as I'm more experienced
in C++ now: "Constructors without implicit type conversion".
I'm aware that this topic has been discussed in other posts/proposols but
I'm still not satisfied. I also know that this feature is unnecessary, as one
can use NonConverting classes,i.e
template<class T> class NonConverting
{ private: T value;
public : NonConverting(T v) : value(v) {};
operator T () { return value; };
};
But in my opinion the use of NonConverting-classes just to prevent the
compiler to do implicit type conversion makes the source code harder to read.
Besides, I like to have "while();", "do { } while();" and "for(..;..;..);"
loops, allthough i.e. the "for"-construct would be sufficient.
So I suggest a constructor !X
(similiar to ~X, "!" stands for no implicit type conversion)
class X
{ ....
public : !X(Type y) { ... };
}
to be a constructor without allowing implicit type conversions.
This should be easy to implement and hould not break existing code,
as I don't beleave that this syntax occurs to often in existing software.
Having both type of constructors ( with or without implicit type conversion)
one can decide to use the advantages of implicit type-conversion or not.
Regards Peter Schmitteckert
P.S. Please apollogize for insisting on this topic, but I'm living in the
`C++-diaspora` of physicist and want to implement some advanced
numerical classes. I really like source-code to be as readable as
possible. Besides I have a lot `experience` with FORTRANs implicit
conventions.
------------------------------------------------------------
Peter Schmitteckert
Lehrstuhl fuer Theoret. Physik 2
Institut fuer Physik
D 86135 Uni Augsburg
e-mail: Peter.Schmitteckert@Physik.Uni-Augsburg.de
Phone: +49-821-5977-246
Fax: +49-821-5977-262
Author: peters@phibm60c.Physik.Uni-Augsburg.DE (Peter Schmitteckert (Tel. 5977-246))
Date: Mon, 24 Jan 1994 20:01:05 GMT Raw View
Hallo ,
some time ago I asked in comp.lang.c++ if there's a opportunity to
have one-argument constructors without implicit type conversion.
Author: damian@cs.monash.edu.au (Damian Conway)
Date: Wed, 26 Jan 1994 02:24:12 GMT Raw View
peters@phibm60c.Physik.Uni-Augsburg.DE (Peter Schmitteckert (Tel. 5977-246)) writes:
> some time ago I asked in comp.lang.c++ if there's a opportunity to
> have one-argument constructors without implicit type conversion. From
> the answers I got I conclude that there is no way.
You didn't ask the right people then :-)
> Wouldn't it be nice to have a contructor without implicit type
> conversion ? I suggest a ctor !X (similiar to ~X, "!" stands for no
> implicit type conversion)
> class X
> { ....
> public : !X(Type y) { ... };
> }
> to be a constructor without allowing implicit type conversion.
You can already do what you want in C++, as it is.
I don't understand anti-commuting variables either, so consider this stack
example:
/***** FixedStack.C ***********************************************************/
class NonConvertingInt
{
private:
int value;
public:
NonConvertingInt(int v) : value(v) {}
operator int (void) { return value; }
};
class FixedStack
{
private:
int size;
public:
FixedStack(NonConvertingInt stacksize) : size(stacksize) {}
FixedStack & operator= (const FixedStack & s) { return *this; }
};
main()
{
FixedStack s(100);
s = 200;
}
/******************************************************************************/
Under g++, this code generates the following error message:
FixedStack.C:27: bad argument 1 for function
FixedStack::operator = (const class FixedStack&)
(type was int )
Under cfront:
"FixedStack.C", line 27: error: bad operand types FixedStack int for =
Voila!
damian
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
who: Damian Conway email: damian@bruce.cs.monash.edu.au
where: Dept. Computer Science phone: +61-3-565-5184
Monash University fax: +61-3-565-5146
Clayton 3168 quote: "A pessimist is never disappointed."
AUSTRALIA