For example I would like to simplify the std::tr1::shared_pointer template class. I would like to have an alias for std::tr1::shared_pointer.
But this doesn’t work:
#include <tr1/memory>
template <class T>
class SharedPointer : public std::tr1::shared_ptr<T>
{
};
int main(int argc, char *argv[])
{
SharedPointer<int> test(new int(5));
return 0;
}
Since the constructors are not inherited.
Is there a pattern to solve this?
If you want to alias it, a
usingdeclaration will create a true alias, rather than a subclass:Edit
A method that should work on GCC 4.6.* compilers would be to make a wrapper function around the
std::tr1::shared_ptr<T>. Since GCC 4.6.* supports the C++11 library, I’ve used that instead of TR1: