Typedef for template type

What happened to the following?

typedef boost::shared_ptr SharedPtr;

GCC gives the following error:

ISO C ++ forbids declaring 'shared_ptr without type

+5
source share
1 answer

C ++ does not yet have a "typedefs template" where you can "rename" such a template. This function is added in C ++ 0x, where such a "typedef" is called an "alias pattern".

The simplest workaround that works today is to use a class template with a nested typedef:

template <typename T>
struct SharedPtr
{
    typedef std::shared_ptr<T> Type;
};

// usage
typename SharedPtr<int>::Type sp;
+6
source

All Articles