我試圖在一個嵌入式項目中使用shared_ptr
,該嵌入式項目使用xc32 1.34(gcc 4.5.2的派生版)構建。該項目已通過-fno-rtti
禁用RTTI。shared_ptr沒有RTTI?
#include <memory>
就包括頭給了我以下錯誤:
/Applications/microchip/xc32/v1.34/bin/bin/../../lib/gcc/pic32mx/4.5.2/../../../../pic32mx/include/Cpp/memory: In member function 'virtual void* std::tr1::_Ref_count_del<_Ty, _Dx>::_Get_deleter(const std::type_info&) const':
In file included from APP/MODULES/LIGHT_MANAGER/LightManager.cpp:13:0:
/Applications/microchip/xc32/v1.34/bin/bin/../../lib/gcc/pic32mx/4.5.2/../../../../pic32mx/include/Cpp/memory:1264:39: error: cannot use typeid with -fno-rtti
/Applications/microchip/xc32/v1.34/bin/bin/../../lib/gcc/pic32mx/4.5.2/../../../../pic32mx/include/Cpp/memory: In member function 'virtual void* std::tr1::_Ref_count_del_alloc<_Ty, _Dx, _Alloc>::_Get_deleter(const std::type_info&) const':
/Applications/microchip/xc32/v1.34/bin/bin/../../lib/gcc/pic32mx/4.5.2/../../../../pic32mx/include/Cpp/memory:1299:39: error: cannot use typeid with -fno-rtti
/Applications/microchip/xc32/v1.34/bin/bin/../../lib/gcc/pic32mx/4.5.2/../../../../pic32mx/include/Cpp/memory: In function '_Dx* std::tr1::get_deleter(const std::tr1::shared_ptr<_Ty2>&)':
/Applications/microchip/xc32/v1.34/bin/bin/../../lib/gcc/pic32mx/4.5.2/../../../../pic32mx/include/Cpp/memory:1956:44: error: cannot use typeid with -fno-rtti
所以我想知道的是:這是一般不可能用shared_ptr
沒有RTTI,還是我做錯了什麼?
沒有RTTI的C++不再是C++。所有(我的意思是*全部*)投注都關閉。誰保證你可以在沒有RTTI的情況下使用''或''或''? –
'shared_ptr'鍵入 - 擦除需要RTTI的刪除器。我認爲沒有辦法編寫自己的代碼或找到一個不這樣做的實現。不幸的是'boost :: shared_ptr'也支持刪除器,也許你可以找到一個沒有的版本。 – nwp
@nwp類型擦除不需要RTTI。通常的模式是實現抽象類的模板包裝類。 – Quentin