可能重複:
What is the difference between (type)value and type(value)?類型(可變)VS(類型)可變
我主要是C#開發人員等使用的語法像做了很多明確的鑄造:(type)variable
,以(int)100.0004d
爲例。因此,當用C++編寫代碼時,我經常使用相同的語法。但是,在其他使用語法type(variable)
與int(100.0004)
作爲示例實現相同演員的情況下,我已經看到(甚至使用過)代碼。
我只是好奇兩種方法之間的區別是什麼,以及是否有任何影響使用一個在另一個。
實施例:
double someDouble = 100.00456;
// Cast the double using the (type)variable syntax
int firstCastValue = (int)someDouble;
// Cast the double using the type(variable) syntax
int secondCastValue = int(someDouble);
你應該使用'static_cast'比任何這些! – 2012-01-16 14:12:13
@GeorgFritzsche乾杯 - 在寫問題之前,我試着找到這樣的文章/ SO貼子。 – 2012-01-16 14:17:28
你受到這樣一個事實的影響:('不是最簡單的字符搜索...:/ – 2012-01-16 14:55:09