tom@tnosoes.UUCP (Tom Vijlbrief) (01/26/89)
When compiling a file of the OOPS package, G++ (1.32) produced an
errormessage for the following function:
=========================
void Time::printOn(ostream& strm)
{
register unsigned hh = hour();
#if 1
((Date)*this).printOn(strm); // Error !
#else
((Date *)this)->printOn(strm); // No Error !
#endif
strm << form(" %d:%02d:%02d ",
(hh <= 12) ? hh : hh-12,
minute(),
second());
if (hh < 12) strm << "am";
else strm << "pm";
}
=========================
In function void Time::printOn (struct ostream &):
Time.c:258: both constructor and type conversion operator apply
===========================
The alternative does not produce an error.
Are these two equivalent and is this a compiler bug ?
Tom
===============================================================================
Tom Vijlbrief
TNO Institute for Perception
P.O. Box 23 Phone: +31 34 63 62 77
3769 ZG Soesterberg E-mail: tnosoes!tom@mcvax.cwi.nl
The Netherlands or: uunet!mcvax!tnosoes!tom
===============================================================================diamond@csl.sony.JUNET (Norman Diamond) (01/27/89)
In article <435@tnosoes.UUCP>, tom@tnosoes.UUCP (Tom Vijlbrief) writes: > When compiling a file of the OOPS package, G++ (1.32) produced an > errormessage for the following function: > ((Date)*this).printOn(strm); // Error ! When you cast the result of *this, it is like assigning the result of *this to a temporary variable of type Date. When you give a command to a temporary variable and then have no further use for that variable, you don't accomplish much. > ((Date *)this)->printOn(strm); // No Error ! Aha. When you have sort of a temporary variable of type (Date *), it still points to your own instance. You then command your own instance to do something, and you get what you want. -- Norman Diamond, Sony Computer Science Lab (diamond%csl.sony.jp@relay.cs.net) The above opinions are my own. | Why are programmers criticized for If they're also your opinions, | re-inventing the wheel, when car you're infringing my copyright. | manufacturers are praised for it?