Topic: bool() -- a defect or inconsistence


Author: "Sektor van Skijlen" <sektor@spam-buffer.aldec.com>
Date: Thu, 13 Sep 2001 06:44:32 GMT
Raw View
"Radoslav Getov" <nospam@mai.com> wrote in message
news:tmbe9tk7lq6442@corp.supernews.com...
> For some strange reason I used to think that 'int j' does not initialize
> 'j', while e.g int j= int() initializes it to 0 (and similarly for the
other
> built-in types).

I thought some time ago about this construction and I mean one
inconsistence.
Take a look:

class Int
{
    int x;
public:
    Int(): x( 0 ) { }
    Int( int xx ): x( xx ) { }
};

Now, if you create new dynamic objects of Int and int, you have:

Int* x = new Int; // initializes to 0
int* y = new Int(); // initializes to 0
Int* z = new Int( 10 ); // initializes to 10

Now, the same statements with int mean:

int* x = new int; // leaves singular
int* y = new int(); // initializes to 0
int* z = new int( 10 ); // initializes to 10

The inconsistence is about this constructor call without parentheses. For
POD types it leaves
it singular, while for user-defined types it means the same as with empty
parentheses.

Some time ago I thougut about the additional meaning for the 'explicit'
keyword. You
can use it now for each constructor with strictly one argument. And also for
other
constructors, but in this case this keyword has no effect. There could be
meant,
that if you mark the zero-argument constructor as 'explicit', then you can
call it
ONLY with the empty parentheses. And in this case, there are two
possibilities
for the constructor call without parentheses if this constructor is
explicit:
 - such a statement is illegal and refused by compiler
 - this statement leaves the newly created object singular

It is worth to solve this, because every inconsistence in the language
definition
(this is very important in this case, because this construction affects both
POD
types and structural types as well and the reason is its usage in templates)
makes it worse quality.



---
[ 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://www.research.att.com/~austern/csc/faq.html                ]