【发布时间】:2016-10-31 09:33:34
【问题描述】:
在我当前的项目中,我们同时为 Linux 和 Windows 构建。 不幸的是,由于一些平台问题,我们的 MSVC 已经很老了。我们使用的是 MSVC 2010。而 gcc 我们使用的是相对较新且更智能的版本,其版本为 4.8 。
下面的代码在 gcc 中编译,但 MSCV 对它唠叨不休:
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);
}
在我为 std::tr1::shared_ptr 添加第二个重载后,MSVC 开始唠叨。 我反复遇到的编译错误:
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>'
你们对我的情况有解决方案吗?
【问题讨论】:
-
#ifdef它在平台上不起作用? -
其中一个可能是
using shared_ptr = the other one。在这种情况下,它是同一类型,不能用于重载。 -
@Yakk 我希望我可以轻松测试它,但是一旦我做出更改,自动构建机器将被触发并且构建过程将需要 1-2 小时。不幸的是,我需要先确定,然后再申请。
-
@BoPersson 我认为这也是问题所在。但正如我在前面所说的那样。不幸的是,我需要确定至少喜欢 %90% 的评论。
标签: c++ c++11 visual-c++ shared-ptr