gjditchfield@watmsg.waterloo.edu (Glen Ditchfield) (07/30/88)
Are conversion operators supposed to be inherited in the same way as other
member functions?
Here is an example:
----------------------------------------
class base {
void* p;
public:
base(void* p) { base::p = p; };
void* asVoid() { return p; };
operator void*() { return p; };
};
class derv:public base {
public:
derv(void* p):(p) {};
};
main() {
base b(0);
derv d(0);
b.asVoid();
d.asVoid();
(void*)b;
(void*)d;
}
----------------------------------------
AT&T C++ (v 1.2.1) gives the error message
... line 20: error: cannot cast class object to pointer
so operator void*() was not inherited, although asVoid() was. On the other
hand, G++ 1.21 makes no complaints about this code. Which of the two
compilers is doing the right thing?
(If we get to vote, I vote for making converstion operators inheritable.)
Glen Ditchfield gjditchfield@violet.uwaterloo.ca Office: DC 2517
Dept. of Computer Science, U of Waterloo, Waterloo, Ontario, Canada, N2L 3G1
Each age thinks itself in possession of the true and
only view possible for sensible man -- W. M. Dixon
--
Glen Ditchfield {watmath,utzoo,ihnp4}!watrose!gjditchfield
Dept of Computer Science, U of Waterloo (519) 885-1211 x6658
Waterloo, Ontario, Canada Office: MC 2006
If you grab the bull by the horns, you at least confuse him -- R.A.Heinlein