C++ Visual Studio 2012中的模板别名

C++ Visual Studio 2012中的模板别名,c++,visual-studio,visual-studio-2012,C++,Visual Studio,Visual Studio 2012,我目前正在尝试将代码移植到Visual Studio 2012,以使用模板别名,如下所示: template< typename T > using SmartPtr = std::shared_ptr< T >; 使用SmartPtr=std::shared_ptr的模板; 但是,Visual Studio 2012不支持模板别名 是否有可能用不会破坏使用它的代码的等价物替换上述声明 关于模板 template< typename T > struct

我目前正在尝试将代码移植到Visual Studio 2012,以使用模板别名,如下所示:

template< typename T > using SmartPtr = std::shared_ptr< T >;
使用SmartPtr=std::shared_ptr的模板; 但是,Visual Studio 2012不支持模板别名

是否有可能用不会破坏使用它的代码的等价物替换上述声明

关于
模板
template< typename T >
struct SmartPtr
{
    typedef std::shared_ptr< T > type;
};
结构SmartPtr { typedef std::shared_ptrtype; };
将其用作:

SmartPtr<int>::type
SmartPtr::type

您可以尝试使用宏:

#define SmartPtr std::shared_ptr;

工作原理与VS2015上的模板别名相同

是否用于专门化?继承可能是一种解决方法。但这仍然意味着我必须用SmartPtr::type right替换SmartPtr代码中的每个实例?@user5024425是的,但如果你不能使用模板别名,那就是你必须做的。嗯,如果我尝试继承:templatestruct SmartPtr:public std::shared\u ptr{};这会带来问题吗?@user502425这是运行时而不是编译时。@user502425您需要通过构造函数。