說我有在C-庫返回布爾值到C-環境
int (*fptr)(void);
一個函數指針和我有在C++類
class A { static int func(); }
我可以做以下,這將是安全的任何平臺
ftpr = A::func;
上我想爲A::func()
返回bool
。
class A { static bool func(); }
,我不介意鑄造
fptr = reinterpret_cast<int(*)()>(A::func);
但它會是任何平臺上安全嗎?乍一看,它似乎會(只要sizeof(bool) <= sizeof(int)
),但我不太確定。
請注意http fomatting ate type reinterpret_cast – zzz777 2012-01-06 18:07:39
僅供參考:您可以縮進四個空格的代碼以將其格式化爲代碼。 – 2012-01-06 18:10:08