lundi 31 octobre 2016

Casting std::tr1::shared_ptr

In my current project we are building for Linux and Windows at the same time. Unfortunately because some platform issues our MSVC is very old. We are using MSVC 2010. And gcc we are using relatively new and smarter which has the version 4.8 .

The code below compile in gcc but MSCV nags about it :

template<class T, class U>
std::shared_ptr<T> Cast( const std::shared_ptr<U>& spObject )   // rename from CastTerrainObject
{
    return std::dynamic_pointer_cast<T>(spObject);
}

template<class T, class U>
std::tr1::shared_ptr<T> Cast( const std::tr1::shared_ptr<U>& spObject ) // rename from CastTerrainObject
{
    return std::tr1::dynamic_pointer_cast<T>(spObject);
}

MSVC began nagging after I add the second overload for std::tr1::shared_ptr. The compile errors I am getting repeatedly :

error C2995: 'std::tr1::shared_ptr<_Ty> Cast(const std::tr1::shared_ptr<_Ty2> &)' : function template has already been defined

And 

 error C2440: 'initializing' : cannot convert from 'std::tr1::shared_ptr<_Ty> (__cdecl *)(const std::tr1::shared_ptr<_Ty2> &)' to 'std::tr1::shared_ptr<_Ty>'

Do you guys have a solution for my case?

Aucun commentaire:

Enregistrer un commentaire