I'm a masochist so I build with these flags: -Wall -W -Wextra -Werror -Wcast-qual -Wc++0x-compat -std=c++0x and a lot more, [s][n][f]printf formatting, switch and for statement stuff, unused parameters, read only string literals etc.
I always try to avoid dynamic_cast, can you replace it with an "IsA" function and static_cast? Or: bool IsGISCompositeClass() const { return (type == gis_Composite; } Or even: virtual bool IsGISCompositeClass() { return false; }
Hi Chris, Re: dynamic cast...I need to examine the situation more carefully, but the class hierarchy has virtual base classes...I used some 'static' type checking (is my type X) to improve performance, because dynamic cast inside inner loops shows up on a perf profile. But..the whole project is sort of deeply in the dynamic type world. That'll have to be another blog post; it's not normally a style I like (and I am a big fan of static typing) but there were a lot of cases where independent subsystems had to be specialized in peculiar combinations to meet UI needs...
You mean you use multiple inheritance from base classes ? That's generally a bad solution leading to lots of problems.
Depending on the width of the class hierarchy it could be better to add an AsGISComposite() method to your base class(classes) returning a pointer to GisComposite where applicable, NULL otherwise, rather than IsGisCompositeClass(), which would doesn't get you rid of the dynamic_cast<>() in the case of multiple inheritance AND no pointer casting in the case of single inheritance.
I take it you build without warnings, then.
ReplyDelete-wall can be very judgmental.
-wall hurts my self esteem. :-)
ReplyDeleteI'm a masochist so I build with these flags:
ReplyDelete-Wall -W -Wextra -Werror -Wcast-qual -Wc++0x-compat -std=c++0x
and a lot more, [s][n][f]printf formatting, switch and for statement stuff, unused parameters, read only string literals etc.
I always try to avoid dynamic_cast, can you replace it with an "IsA" function and static_cast? Or:
ReplyDeletebool IsGISCompositeClass() const { return (type == gis_Composite; }
Or even:
virtual bool IsGISCompositeClass() { return false; }
Hi Chris,
ReplyDeleteRe: dynamic cast...I need to examine the situation more carefully, but the class hierarchy has virtual base classes...I used some 'static' type checking (is my type X) to improve performance, because dynamic cast inside inner loops shows up on a perf profile. But..the whole project is sort of deeply in the dynamic type world. That'll have to be another blog post; it's not normally a style I like (and I am a big fan of static typing) but there were a lot of cases where independent subsystems had to be specialized in peculiar combinations to meet UI needs...
You mean you use multiple inheritance from base classes ? That's generally a bad solution leading to lots of problems.
ReplyDeleteDepending on the width of the class hierarchy it could be better to add an AsGISComposite() method to your base class(classes) returning a pointer to GisComposite where applicable, NULL otherwise, rather than IsGisCompositeClass(), which would doesn't get you rid of the dynamic_cast<>() in the case of multiple inheritance AND no pointer casting in the case of single inheritance.