Boost logo

Boost :

From: Jeremy Graham Siek (jsiek_at_[hidden])
Date: 2004-08-08 10:09:15


Hello Dave,

Sorry about the confusion. I should have distinguished between how this
works in C++, and what is theoretically possible. The contravariance rule I
spoke of describes what makes sense theoretically. However, C++ is more
conservative in this case and restricts parameter types of overloads to be
the same type. This is a similar issue to covariant return types. Early on,
C++ did not allow them, even though it made sense theoretically, then later
on covariant return types were allowed.

Best Regards,
Jeremy

On 8/8/04 2:09 AM, "Dave" <better_cs_now_at_[hidden]> wrote:

>
> Hello all,
>
> Quoting from page 24 of "The Boost Graph Library; User Guide and Reference
> Manual":
>
> "It turns out that by the contravariance subtyping rule, the parameter type
> in the derived classes member function must be either the same type or a
> base class of the type as the parameter in the base class."
>
> Now please consider this code:
>
> #include <iostream>
>
> struct base_1 {};
> struct derived_1: base_1 {};
>
> struct base_2
> {
> virtual void foo(derived_1 *p) {std::cout << "base_2::foo()\n";}
> };
>
> struct derived_2: base_2
> {
> virtual void foo(base_1 *p) {std::cout << "derived_2::foo()\n";}
> };
>
> int main()
> {
> base_2 *ptr = new derived_2;
> ptr->foo(new derived_1);
> }
>
> This outputs base_2::foo(). Why?
>
> The quoted passage implies derived_2::foo() should override base_2::foo().
> Clearly, it does not. Furthermore, I cannot find anything in the Standard
> that indicates it should. So, I am clearly misinterpreting the quoted
> passage. Can anybody explain to me what was meant in that passage?
>
> Thank you,
> Dave
>
>
>
>
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

_______________________________________________
Jeremy Siek <jsiek_at_[hidden]>
http://www.osl.iu.edu/~jsiek
Ph.D. Candidate, Indiana University Bloomington
C++ Booster (http://www.boost.org)
_______________________________________________


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk