編譯器錯誤 C3849
對類型 'type' 運算式的函式樣式呼叫會放棄 const 和/或 volatile 限定詞 (針對所有的 number 可用運算子多載)
具有指定 const-volatile 類型的變數只能呼叫以相同或更大 const-volatile 限定性定義的成員函式。
若要修正此錯誤,請提供適當的成員函式。 當轉換造成限定性遺失時,您無法在 const 或 volatile 限定物件上執行轉換。 您可以取得限定符,但無法在轉換中失去限定符。
下列範例會產生 C3849:
// C3849.cpp
void glbFunc3(int i, char c)
{
i;
}
typedef void (* pFunc3)(int, char);
void glbFunc2(int i)
{
i;
}
typedef void (* pFunc2)(int);
void glbFunc1()
{
}
typedef void (* pFunc1)();
struct S4
{
operator ()(int i)
{
i;
}
operator pFunc1() const
{
return &glbFunc1;
}
operator pFunc2() volatile
{
return &glbFunc2;
}
operator pFunc3()
{
return &glbFunc3;
}
// operator pFunc1() const volatile
// {
// return &glbFunc1;
// }
};
int main()
{
// Cannot call any of the 4 overloads of "operator ()(.....)" and
// "operator pFunc()" because none is declared as "const volatile"
const volatile S4 s4; // can only call cv member functions of S4
s4(); // C3849 to resolve, uncomment member function
}