我想轉換爲int(或unsigned int)的指針,無論我嘗試它不想工作。的空調風格錯誤:從'美孚*'轉換爲'無符號詮釋'失去精度
我試過static_cast<intptr_t>(obj)
,reinterpret_cast<intptr_t>(obj)
,以及各種組合投射,intptr_t
的,unsigned int
的,而我包括stdint.h。從我讀過的內容來看,我嘗試過的很多事情中的一件應該是有效的。是什麼賦予了?
我沒有理會包括代碼,因爲它正是我所描述的,但既然你問,我已經嘗試了所有這些再加上其他的組合:
void myfunc(Foo* obj)
{
// ...
uintptr_t temp = reinterpret_cast<uintptr_t>(obj);
uintptr_t temp = static_cast<uintptr_t>(obj);
uintptr_t temp = (uintptr_t)obj;
intptr_t temp = reinterpret_cast<intptr_t>(obj);
intptr_t temp = static_cast<intptr_t>(obj);
intptr_t temp = (intptr_t)obj;
unsigned int temp = reinterpret_cast<unsigned int>(obj);
unsigned int temp = static_cast<unsigned int>(obj);
unsigned int temp = (unsigned int)obj;
// ...
}
他們都給出確切的同樣的錯誤。
你在鑄造的?告訴我們問題不是這一步。 – GManNickG 2010-10-09 22:36:59
你爲什麼這樣做?此外,請包括問題代碼。 – JoshD 2010-10-09 22:38:05
你使用什麼編譯器? – 2010-10-09 22:44:52