2011-08-21 75 views
1

我最近開始使用NDK將應用程序移植到Android和我遇到了以下錯誤:Visual Studio如何使用boost :: function和/ GR-而GCC不能使用-fno-rtti?

boost/function/function_base.hpp:220: error: cannot use typeid with -fno-rtti. 

通常情況下,我會毫不猶豫地有關的錯誤,但Visual Studio項目文件中設置/GR-,禁用RTTI並且使用boost :: function沒有問題。

我的理論是這樣的,因爲當靜態類型可以被確定時,typeid被編譯器忽略,所以在應用程序中每次使用boost :: function都必須是這種情況。 Visual Studio必須首先嚐試確定靜態類型,而GCC會在嘗試評估它之前立即在typeid上引發錯誤。

這聽起來沒錯嗎?如果不是,發生了什麼事?

+1

BOOST_NO_TYPEID是否在兩個不同的編譯器之間一致定義? – selbie

+0

你爲什麼要嘗試? – wilx

+0

@selbie這兩種情況都沒有定義。我看了一下function.hpp和function/function_base.hpp,並沒有檢查那個符號。我嘗試添加它,但沒有什麼區別。 – IronMensan

回答

2

我沒有啓動進入我的Windows分區,但是在MSDN中查看這一點非常簡單。

this link on MSDN

If the expression is dereferencing a pointer, and that pointer's value is zero, typeid throws a bad_typeid exception. If the pointer does not point to a valid object, a __non_rtti_object exception is thrown, indicating an attempt to analyze the RTTI that triggered a fault (like access violation), because the object is somehow invalid (bad pointer or the code wasn't compiled with /GR).

If the expression is neither a pointer nor a reference to a base class of the object, the result is a type_info reference representing the static type of the expression. The static type of an expression refers to the type of an expression as it is known at compile time.....

換句話說,如果表達式的類型不能在編譯時推斷,並沒有/ GR,那麼你會得到一個異常或編譯器錯誤。但第二段暗示它可以在編譯時推斷非模糊類型。

+0

作爲澄清的一點,您是否同意我在嘗試執行此操作之前在有關GCC生成錯誤的問題中所說的內容? – IronMensan

+0

你的理論與MSDN暗示的一致。 – selbie

相關問題