说我有在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