[英]C++11 Android vector of pointers push_back doesn't work with libstdc++
使用STLPort时,以下代码编译正常:
std::vector<Engine::Screen::IOverlay*> Overlays;
auto TestOverlay=new Engine::Screen::Overlay();
Overlays.push_back(TestOverlay);
但是在使用libstdc ++进行编译时,由于某种原因,它试图使用move构造函数:
error : cannot bind 'Engine::Screen::IOverlay*' lvalue to 'Engine::Screen::IOverlay*&&' ...\android-ndk-r8\sources\cxx-stl\gnu-libstdc++\include\bits\move.h
这是一个非常基本的示例,但是在使用push_back时,所有本地指针的应用程序都会出现此问题。
move.h中发生错误:
template<typename _Tp>
inline typename std::remove_reference<_Tp>::type&&
move(_Tp&& __t)
{ return __t; }
例2(我写的另一个基本测试:)
class TestClass {};
auto TestInstance=new TestClass;
std::vector<TestClass*> TestVector;
TestVector.push_back(TestInstance);
我用ndk r8编译:-std = c ++ 11 -D__STDC_INT64__
似乎编译器中有两个错误。 首先它错误地调用push_back(T&&)
,然后尝试移动对象,这是不正确的:
template<typename _Tp>
inline typename std::remove_reference<_Tp>::type&&
move(_Tp&& __t)
{ return __t; }
它应该实现为:
template<class _Tp>
typename remove_reference<_Tp>::type&&
move(_Tp&& __t) noexcept //noexcept should be here!
{
return static_cast<typename remove_reference<_Tp>::type&&>(__t);
}
这意味着您的编译器在此上下文中显示两个错误:
push_back(T&&)
。 std::move
执行不正确 您使用的是哪个版本的编译器?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.