Quickie - templated typedef?
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.
template<typename T>struct MySmartPtr { typedef boost::SharedPtr<T> type;private: MySmartPtr();};// use:MySmartPtr<int>::type smart_int_ptr;
#include <boost/shared_ptr.hpp>namespace mylib{ using boost::shared_ptr;}mylib::shared_ptr<int> ptr;
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]
[Edited by - SiCrane on June 26, 2006 10:18:24 AM]
Okay, thanks for the answers guys. I guess I need to use an ugly hack to get my idea to compile after all...
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]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement