6

Can someone explain the ambiguity here?

template <typename...> struct thing;

template <typename... Rest>
struct thing<int&, Rest&...> {
    thing(int&, Rest&...) { }
};

template <typename First, typename... Rest>
struct thing<First&, Rest&...> {
    thing(First&, Rest&...) { }
};

int main() {
    int myint;
    char mychar;
    thing<int&, char&> t(myint, mychar);
}
prestokeys
  • 4,817
  • 3
  • 20
  • 43

1 Answers1

0

if you specialize on int instead of int& it works

template <typename...> struct thing;

template <typename... Rest>
struct thing<int, Rest...> {
    thing(int&, Rest&...) { }
};

template <typename First, typename... Rest>
struct thing<First, Rest...> {
    thing(First&, Rest&...) { }
};
sp2danny
  • 7,488
  • 3
  • 31
  • 53