简体   繁体   English

模糊的模板实例化

[英]Ambiguous template instantiation

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

if you specialize on int instead of int& it works 如果你专注于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&...) { }
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM