[Gdal-dev] RE: need RTTI for OGR (Windows)
Mateusz Łoskot
mateusz at loskot.net
Tue Apr 11 13:58:37 EDT 2006
Chapman, Martin wrote:
> [...] You will just have to use a C style cast like:
It's better to use C++ static_cast<>() operator than C style.
> OGRGeometry *poGeometry .... // not null ... switch
> (poGeometry->getGeometryType()) { ..... case wkbPolygon: MyFunc(
> (OGRPolygon*)poGeometry);
MyFunc( static_cast<OGRPolygon*>(poGeometry) );
Here static_cast<>() will work well because it's used to cast
down the hierarchy what's very common/.
NOTE: when if poGeometry points not to OGRPolygon
base class, then it will cause run-time error.
So, it's not safer than dynamic_cast but safer than C style.
NOTE 2: static_cast<>() is very native and
does not decrease performance in any way.
NOTE 3 about NOTE 2:
Generally, casting is pretty expansive operation, so there is always
some overhead :-)
Cheers
--
Mateusz Łoskot
http://mateusz.loskot.net
More information about the Gdal-dev
mailing list