2013年7月27日 星期六

資料型態轉型 Type Casting

Compile-time casting

unary operator with syntax: DataType(expression)

Ex: double(9)/2

Run-time casting

requested conversion checked at runtime, appiled if valid.

syntax: static_cast<DataType>(expression)

Ex: static_cast<double>(9)/2

兩者在效率上有所差別。
沒記錯的話,
應該是 Run-time casting 比較優。

 

沒有留言:

張貼留言