編譯器錯誤 C3066
有多種方式可以用這些引數呼叫這種類型的物件
編譯程式偵測到涉及 Surrogates 的模棱兩可函數調用。
下列範例會產生 C3066:
// C3066.cpp
template <class T, class U> void func(T*, U*){}
typedef void (*PF)(const int*, const char*);
typedef void (*PF1)(const int*, volatile char*);
struct A {
operator PF() const {
return func;
}
operator PF1() {
return func;
}
operator PF1() const {
return func;
}
};
int main() {
A a;
int i;
char c;
a(&i, &c); // C3066
a(&i, (const char *) &c); // OK
}
Copy-list-initialization
在 Visual Studio 2015 中,編譯器會使用與一般 copy-initialization 相同的方式錯誤地處理 copy-list-initialization;它只會考慮轉換建構函式來進行多載解析。 在下列範例中,Visual Studio 2015 會選擇 MyInt(23),但 Visual Studio 2017 會正確地引發錯誤。
// From http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_closed.html#1228
struct MyList {
explicit MyStore(int initialCapacity);
};
struct MyInt {
MyInt(int i);
};
struct Printer {
void operator()(MyStore const& s);
void operator()(MyInt const& i);
};
void f() {
Printer p;
p({ 23 }); // C3066: there are multiple ways that an object of this type can be called with these arguments
}