Jump to content
  • Advertisement
Sign in to follow this  

Quickie - templated typedef?

This topic is 4349 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

Hi, I just have a quick question, I couldn't really find the answer for (after I've tried and tried to solve it myself). I want to make a templated typedef if that's possible? It's because I've come to three possible solutions to my needs: 1. typedef boost::shared_ptr<Class> ClassPtr or class Class { typedef boost::shared_ptr<Ptr>; } 2. template<class T> SharedPtr : public boost::shared_ptr<T> { boost::shared_ptr wrapper implementation } 3. This is the one, I really want but cannot define properly. Something like SharedPtr<Class> (where SharedPtr is just a typedef) which I think could be made as so: typedef template<class T> SharedPtr<T> or template<class T> typedef SharedPtr<T> But since none of these are legal ways to typedef a templated class, I'm asking if I can do it the way I want, or do I have to use one of the other methods? EDIT: The reason for wanting to use a typedef in this case is that I am able to replace it with another implementation or my own later if needed.

Share this post


Link to post
Share on other sites
Advertisement

template<typename T>
struct MySmartPtr {
typedef boost::SharedPtr<T> type;
private:
MySmartPtr();
};

// use:
MySmartPtr<int>::type smart_int_ptr;

Share this post


Link to post
Share on other sites
#include <boost/shared_ptr.hpp>

namespace mylib
{
using boost::shared_ptr;
}

mylib::shared_ptr<int> ptr;

Share this post


Link to post
Share on other sites
Templated typedefs are not a current part of the C++ standard. They should make it into the next version (although the syntax looks a little stringstrange IMO).

[Edited by - SiCrane on June 26, 2006 10:18:24 AM]

Share this post


Link to post
Share on other sites
Okay, thanks for the answers guys. I guess I need to use an ugly hack to get my idea to compile after all...

Share this post


Link to post
Share on other sites
Quote:
Original post by nife
Okay, thanks for the answers guys. I guess I need to use an ugly hack to get my idea to compile after all...


Using a namespace is not a ugly hack. [razz]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!