Delen via


Compilerfout C3066

er zijn meerdere manieren waarop een object van dit type kan worden aangeroepen met deze argumenten

Opmerkingen

De compiler heeft een dubbelzinnige functieaanroep gedetecteerd waarbij surrogaten betrokken zijn.

Voorbeelden

In het volgende voorbeeld wordt C3066 gegenereerd:

// 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-lijst-initialisatie

In Visual Studio 2015 behandelde de compiler foutief copy-lijst-initialisatie op dezelfde manier als reguliere copy-initialisatie; hij beschouwde alleen converterende constructors voor overbelastingsoplossing. In het volgende voorbeeld kiest Visual Studio 2015 MyInt(23), maar visual Studio 2017 geeft de fout correct weer.

// From https://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
}