Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

3
  • Indeed, dynamic_cast would be safer than static_cast but I didn't mention it because I've never seen it actually used (I heard about a performance hit but don't know how big it is). Commented Feb 10, 2011 at 20:26
  • 4
    @7vies: In Visual C++ it's about 2 thousand processor cycles and the compiler won't catch you if you cast your COM object to the wrong type - you'll only get a null pointer during runtime. Commented Feb 11, 2011 at 6:10
  • @sharptooth: Yep, dynamic_cast is definitely not the best option in the COM context. I'm not even sure in which situation it could be a good option at all - in most cases it can be replaced by run-time or compile-time polymorphism which would be safer and faster at the same time. Commented Feb 11, 2011 at 11:50