模糊的模板实例化

时间:2017-11-27 13:55:15

标签: c++ c++11 templates ambiguity

有人可以解释这里的含糊不清吗?

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);
}

1 个答案:

答案 0 :(得分:0)

如果您专注于int而不是int&,那么它会起作用

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&...) { }
};
相关问题