>From: "Philip Dunstan" <[EMAIL PROTECTED]>

> Hi there,
>
> Should this work?

No. Template type deduction uses an object's static (declared) type, so in
this program, T=A, since the static type of pa is A*. That its dynamic type
is B* isn't taken into consideration, as template instantiation is done at
compile-time.


Regards,

Terje


> I've tried it using g++ 3.2 (redhat and cygwin) and borland c++ builder
> 5.6.4 and it fails on the assert for all of them.
>
> #include <boost/type_traits.hpp>
> #include <cassert>
>
> class A {};
>
> class B : public A {};
>
> template <typename T>
> bool isDerivedFromA(const T& t)
> {
>     return boost::is_base_and_derived<A, T>::value;
> }
>
> int main()
> {
>     B b;
>     A* pa = &b;
>     assert(isDerivedFromA(*pa));
>     return 0;
> }

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to