運算式的標記法
指定運算元時,C++ 語言會指定特定的相容性。 下表說明需要 type 類型運算元的運算子可接受的運算元類型。
運算子可接受的運算元類型
預期的類型 |
允許的類型 |
---|---|
type |
const type volatile type type& const type& volatile type& volatile const type volatile const type& |
type* |
type* consttype* volatiletype* volatile const |
const type |
typeconst typeconst type& |
volatile type |
typevolatile typevolatile type& |
由於上述規則一律可以搭配使用,因此可以在預期出現指標的位置提供 volatile 物件的 const 指標。