Hello All ...
I'm a newcomer to the C++ language, and have some questions. Thanks in
advance to anyone answering, please feel free to pick only question(s) that
you feel like answering.
First off, would anyone happen to know if/where one might obtain a copy of
the (draft) ANSI C++ standard? If not that, I would also very much welcome an
URL for a copy of the draft ANSI C standard, assuming it also includes the
standard libary functions. I also read the C_ECHO, and remember a new draft
being released? I thought I saved a message announcing it, but now I seem to
have misplaced it. :-)
Should I allow the compiler to allocate enums as single bytes? Or to use
unsigned characters by default? It allows me to set these as options, but I
believe both could get me into portability trouble? What's standard?
When overloading operators for a class, when should I implement the functions
as member functions, and when as friend functions? My textbook demonstrates
both methods, but doesn't say when nor why to use either.
When overloading the "=" operator for class X, should I use
void X::operator=([const] X&);
as my textbook does, or
X& X::operator=([const] X&);
returning "*this", as Borland's online help says I should do? Is there a
difference?
In an exercise which asked to to overload the ++ and -- prefix and postfix
operators for a class, I wrote the following test code:
cout << "a == " << a.GetValue() << "; ++a == " << ++a << endl
<< "a == " << a.GetValue() << "; a++ == " << a++ << endl
<< "a == " << a.GetValue() << "; --a == " << --a << endl
<< "a == " << a.GetValue() << "; a-- == " << a-- << endl
<< "a == " << a.GetValue();
First I was quite surprised by the really wrong output this produced but
after some minutes of hard thought (and cursing buggy compilers), I concluded
this really was to be expected as a result of the cdecl (by the way, is that
an acronymn?) right-to-left style of argument passing.
Indeed, splitting the single cout statement into 9 seperate cout statements
solved the problem, and quite content that I had managed to solve the mystery
I went back through the chapter since I remembered it did something similar,
only to be rewarded with an example where the autor *did* string multiple
statements onto a single cout (not everything as I did, but one line at a
time, one GetValue call and one ++/-- call, which still produced wrong
output, as I now expected) providing the following note:
"Due apparently to a bug in Borland C++ 4.5, using that compiler did not
produce the preceding results. If you experience this problem, repaired in
Borland C++ 5, use the following main function, which divides the multipart
output statements and ensures that the expressions are evaluated in strict
left-to-right fashion: [ 9 couts]"
Pardon? Bug? Annoying as it is, this behaviour is to be expected of cdecl
isn't it? Furthermore, if it is a bug, it doesn't seem fixed...
I guess this is a Borland specific question, but is there any way to stop
name mangling for class member functions? I know that normally, when
implementing functions in an external assembly language module I can declare
them as extern "C" to stop name mangling, but the compiler doesn't seem to
let me do that with member functions.
Rene
---
---------------
* Origin: postmaster@rene.demon.nl (2:282/1.11)
|