Вопрос

I am using Apple's LLVM 4.2 compiler to compile this C++ code. I have overloaded a member function with different tuple combinations, and I believe I am calling the correctly one of them, yet the compiler finds an ambiguity. In essence, I am trying to call method (1) below, yet the compiler finds method (2) also acceptable/compatible. Why is that? I have C++11 flags turned on.

enum class Enum1 { ... }
enum class Enum2 { ... }
enum class Enum3 { ... }
enum class Enum4 { ... }

void myMethod() {
  Enum1 e1;
  Enum2 e2;
  Enum3 e3;
  doSomething({e1,e2,e3}); // should pick (1), yet compiler finds (2) compatible also!?
}

inline void doSomething(const tuple<Enum1,Enum2,Enum3>& p) { // (1)
  ...
}

inline void doSomething(const tuple<Enum1,Enum2,Enum3,Enum4>& p) { // (2)
  ...
}
Это было полезно?

Решение

Are you sure the compiler finds both acceptable, and doesn't say that none are acceptable and lists the candidates? std::tuple's argument-per-element constructor is explicit, and so is not eligible when it comes to copy-initializing the parameter from a braced initializer. In other words, neither function should be selected.

You need to explicitly construct the tuple in the argument.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top