Quickie - templated typedef?

Started by
4 comments, last by Fruny 17 years, 9 months ago
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.
Killers don't end up in jailThey end up on a high-score!
Advertisement
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;
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
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]
Okay, thanks for the answers guys. I guess I need to use an ugly hack to get my idea to compile after all...
Killers don't end up in jailThey end up on a high-score!
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]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement