Topic: PROBLEM: inheritance and polymorphisme
Author: khoda@ptsun05.cern.ch (Arash Khodabandeh)
Date: Thu, 4 Nov 1993 17:13:37 GMT Raw View
Hello all,
Before all i would like to aske for replies by mail,
I will post a summery.
Here is my problem for which I need your help:
I have 4 classes: SA
SB sublcass of SA
A
B subclass of A
class SA class A
{ {
public: }
void F (A PAR);
}
class SB : public SA class B : public A
{ {
public: }
void F (B PAR);
}
So SB redefines the F function defined in SA but the parameter
type of SB:F is B a subtype of the parameter of SA::F.
The bodies of theFs are:
void SA::F (A PAR) { cout << "F of SA" << endl; }
void SB::F (B PAR) { cout << "F of SA" << endl; }
And my main is:
Main () {
sa osa; // line 1
sb osb; // line 2
a oa; // line 3
b ob; // line 4
osa.f(oa); // line 5
osa.f(ob); // line 6
osb.f(oa); // line 7
osb.f(ob); // line 8
}
When I compile with a ATT c++ compiler I get the following message:
"E#669 cannot make a structure B from a A" for the line 7.
But when I compile with g++ version 2.4.5 it compiles and this
is the output:
f of sa // call of line 5
f of sa // call of line 6
f of sa // call of line 7
f of sb // call of line 8
Which measn that the call of F on an object of type SB with
a parameter of type A calls the F of SA.
I agree with the first policy (the ATT c++ compiler).
My questions are:
- which policy is the correct one? the ATT c++ one or the g++ one?
- is there a bug in g++?
- is there a bug in the ATT c++ compiler?
- what the standard recommands?
Please reply by mail I will post a summery.
Many thanks in advance,
Cheers,
Arash Khodabandeh,
CERN ECP, Programming Techniques Group, CH-1211 GENEVE 23,
Phone: + 41 22 767 8072, Fax: + 41 22 767 8730,
Email: Arash.Khodabandeh@cern.ch khoda@ptsun00.cern.ch, akhodaba@cernvax.cern.ch.