[Gdal-dev] RE: need RTTI for OGR (Windows)
Chapman, Martin
MChapman at sanz.com
Tue Apr 11 15:16:01 EDT 2006
Mateusz,
I agree, good point.
Best regards,
Martin
-----Original Message-----
From: gdal-dev-bounces at lists.maptools.org [mailto:gdal-dev-bounces at lists.maptools.org] On Behalf Of Mateusz Loskot
Sent: Tuesday, April 11, 2006 11:59 AM
To: gdal-dev at lists.maptools.org
Subject: Re: [Gdal-dev] RE: need RTTI for OGR (Windows)
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
_______________________________________________
Gdal-dev mailing list
Gdal-dev at lists.maptools.org
http://lists.maptools.org/mailman/listinfo/gdal-dev
More information about the Gdal-dev
mailing list