help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Redundant dynamic_cast<>


From: Thomas Maeder
Subject: Re: Redundant dynamic_cast<>
Date: Wed, 05 Apr 2006 15:27:31 +0200
User-agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Jumbo Shrimp, linux)

Andreas Schallenberg <no_reply@yahoo.com> writes:

> is there any way to make g++ (preferably) report dynamic_cast
> statements that are unnecessary?  Example:
>
> class A{...};
> class B : public A {...};
> class C : public B {...};
> ...
> void myFunc(C * obj)
> {
>   // redundant one...
>   ... = dynamic_cast<C*>(obj);
>   // ...redundant two
>   ... = dynamic_cast<B*>(obj);
> }

Not that I know of.

You could of course write a little function template that
- invokes dynamic_cast if source and destination types are different
- produces a compiler error if both types are equal

and use that function template instead of dynamic_cast.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]