Topic: ? Legal C++ or not ?
Author: zeisel@indmath.uni-linz.ac.at
Date: 29 Sep 1994 11:57:41 -0500 Raw View
Is the following program syntactical legal C++?
(Is an object of a derived class an object of its base class?)
The DEC compiler and Guido Buzzi--Ferraris'
"Scientifc C++", p.415 say "No",
the Borland compiler "Yes".
After carefully reading ARM 4.7 times, I think Borland is right.
---------------------------
class Base
{
};
class Derived: public Base
{
};
void f(Base x)
{
}
int main()
{
Derived b;
f(b);
return 0;
}
---------------------------
Newsfeed unreliable, please answer also via EMail.
-------------------------------------------------------------------
Helmut Zeisel zeisel@indmath.uni-linz.ac.at
Institut fuer Mathematik
Universitaet Linz
A-4040 Linz Tel +43-732-2468-9225
AUSTRIA/EUROPE Fax +43-732-246810
Author: shoe@objectSpace.com (Brett L. Schuchert)
Date: Fri, 30 Sep 1994 22:33:37 GMT Raw View
> class Derived: public Base
> {
> };
>
> void f(Base x)
> {
> }
>
> int main()
> {
> Derived b;
> f(b);
> return 0;
> }
This is legal.
However, when you call your function f, the b object is copied because
f takes a copy of a b, not a reference or a pointer. When the copy
is made, the Base part of b is used for the copy, the derived part
is simple lost.
shoe