编译器错误 C3849
“type”类型的表达式中的函数样式调用会丢失所有 number 个可用运算符重载的 const 和/或 volatile 限定符
具有指定 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
}