TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: THOMAS MAEDER
from: JAN BIJSTERBOSCH
date: 1997-12-22 14:12:00
subject: What`s wrong with this?

Hello Thomas,
17 Dec 97, Thomas Maeder of 2:301/138 wrote to Alberto Monteiro
[ some snipped ]
AM> AM>   Vector(double xx = 0, double yy = 0);    // constructor
AM> TM>This  constructor  may  cause you problems (not in the main() fun
AM> TM>you give below, though) like every constructor taking one argumen
AM> TM>can be used by the compiler for implicit conversions.
[ explanation snipped ]
 TM> explicit Vector(double xx = 0, double yy = 0);    //
 TM> constructor
To kill any compiler warnings, should this not better be written as:
explicit Vector(double xx = 0.0, double yy = 0.0);
In an earlier posting I saw a definition of an overloaded + operator as 
follows:
String operator+ (String &left, String &right)
{
    String str;
    ...
    return str;
}
In my humble opinion this will not work on all compilers (however Borland 
will except it I think) because the moment of deallocation of str is not 
defined in the C++ standard.
I think first of all this operator should be declared as a friend in the 
String class and read as follows:
friend String & operator+ (const String &left, const String &right);
The returning of a reference will create a temporary object thus making the 
moment of deallocation of str unimportant.
 TM> Thomas
Greetings from overcast Amsterdam and best wishes for 1998,
       Jan
email:bijster@worldonline.nl
http://www.worldonline.nl/~bijster
--- MBM v3.41e
---------------
* Origin: Snuffelaar bij DosBoss West (2:500/121.5122)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.