컴파일러 오류 C2668

'function': 오버로드된 함수에 대한 모호한 호출

지정된 오버로드된 함수 호출을 확인할 수 없습니다. 하나 이상의 실제 매개 변수를 명시적으로 캐스팅할 수 있습니다.

템플릿 사용을 통해 이 오류를 가져올 수도 있습니다. 동일한 클래스에 일반 멤버 함수와 동일한 서명을 가진 템플릿 멤버 함수가 있는 경우 템플릿이 지정된 함수가 먼저 와야 합니다. 이 제한은 Visual C++의 현재 구현에서 다시 기본.

예제

다음 샘플에서는 C2668을 생성합니다.

// C2668.cpp
struct A {};
struct B : A {};
struct X {};
struct D : B, X {};

void func( X, X ){}
void func( A, B ){}
D d;
int main() {
   func( d, d );   // C2668 D has an A, B, and X
   func( (X)d, (X)d );   // OK, uses func( X, X )
}

이 오류를 해결하는 또 다른 방법은 선언을 사용하는 것입니다.using

// C2668b.cpp
// compile with: /EHsc /c
// C2668 expected
#include <iostream>
class TypeA {
public:
   TypeA(int value) {}
};

class TypeB {
   TypeB(int intValue);
   TypeB(double dbValue);
};

class TestCase {
public:
   void AssertEqual(long expected, long actual, std::string
                    conditionExpression = "");
};

class AppTestCase : public TestCase {
public:
   // Uncomment the following line to resolve.
   // using TestCase::AssertEqual;
   void AssertEqual(const TypeA expected, const TypeA actual,
                    std::string conditionExpression = "");
   void AssertEqual(const TypeB expected, const TypeB actual,
                    std::string conditionExpression = "");
};

class MyTestCase : public AppTestCase {
   void TestSomething() {
      int actual = 0;
      AssertEqual(0, actual, "Value");
   }
};

상수 0을 사용하는 캐스트의 변환은 둘 다 longvoid*변환이 필요하기 때문에 int 모호합니다. 이 오류를 해결하려면 0을 사용 중인 함수 매개 변수의 정확한 형식으로 캐스팅합니다. 그런 다음 변환이 수행 될 필요가 없습니다.

// C2668c.cpp
#include "stdio.h"
void f(long) {
   printf_s("in f(long)\n");
}
void f(void*) {
   printf_s("in f(void*)\n");
}
int main() {
   f((int)0);   // C2668

   // OK
   f((long)0);
   f((void*)0);
}

CRT에는 이제 float 모든 수학 함수의 형식과 double 형식이 있으므로 이 오류가 발생할 수 있습니다.

// C2668d.cpp
#include <math.h>
int main() {
   int i = 0;
   float f;
   f = cos(i);   // C2668
   f = cos((float)i);   // OK
}

이 오류는 pow(int, int) CRT에서 math.h 제거되었기 때문에 발생할 수 있습니다.

// C2668e.cpp
#include <math.h>
int main() {
   pow(9,9);   // C2668
   pow((double)9,9);   // OK
}

이 코드는 Visual Studio 2015에서 성공하지만 Visual Studio 2017 이상에서는 C2668을 사용하여 실패합니다. Visual Studio 2015에서 컴파일러는 일반 복사 초기화와 동일한 방식으로 copy-list-initialization을 잘못 처리했습니다. 오버로드 확인을 위해 생성자만 변환하는 것으로 간주되었습니다.

struct A {
    explicit A(int) {}
};

struct B {
    B(int) {}
};

void f(const A&) {}
void f(const B&) {}

int main()
{
    f({ 1 }); // error C2668: 'f': ambiguous call to overloaded function
}