Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Casting Smart Pointers

This topic is 5886 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all, Are there any well-known methods for casting between smart pointers of different types? e.g.:

class A

class B : public A

// exactly how you''d declare a smart pointer in my engine:

#define QUILL_DYNAMIC_PTR( x ) Quill::QuillPtr >


// this is impossible, due to C++ type technicalities

So far as I can understand, the only way to do such a thing would be to reimplement my smart pointer class to deal with such cases (at the moment my smart pointer class (QuillPtr) remains the same, whether dealing with new/delete allocated memory or COM pointers - only the RefCounter used by the QuillPtr ever needs to be reimplemented). Does anyone have any ideas? I''ll provide more source code as needed Tom

Share this post

Link to post
Share on other sites
Create a new smart pointer, copy the raw pointer, destroy the old smart pointer.

Have a look at Boost''s smart pointers, or Loki''s (if you like template code).

Magmai Kai Holmlor

"Oh, like you''ve never written buggy code" - Lee

[Look for information | GDNet Start Here | GDNet Search Tool | GDNet FAQ | MSDN RTF[L] | SGI STL Docs | STFW | Asking Smart Questions ]

[Free C++ Libraries | Boost | ACE | Loki | MTL | Blitz++ | wxWindows| Spirit(xBNF)]

Share this post

Link to post
Share on other sites
Thanks very much, but wouldn''t that screw up reference counts for the original pointer? Maybe I''m misunderstanding. Anyway, I''ll check out the boost/Loki source code.

Thanks again


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!