作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
有人能解释一下为什么编译器无法区分这两个专业吗(gcc 4.5.1 @ideone)
template <typename... T> struct S;
template<typename A, typename B, typename... C>
struct S<A, B, C...> {
int f() {return 1;}
};
template<typename... A, typename... C>
struct S< S<A...>, C...> {
int f() {return 2;}
};
当我尝试实例化 S<S<a, b>, a, b> o2;
时编译器提示:
prog.cpp:20:21: error: ambiguous class template instantiation for 'struct S<S<a, b>, a, b>'
prog.cpp:6:22: error: candidates are: struct S<A, B, C ...>
prog.cpp:11:33: error: struct S<S<A ...>, C ...>
prog.cpp:20:21: error: aggregate 'S<S<a, b>, a, b> o2' has incomplete type and cannot be defined
而当最后一个专精改为:
template<typename... A, typename B, typename... C>
struct S< S<A...>, B, C...> {
int f() {return 2;}
}
一切正常。
最佳答案
我对这个问题的理解:
typedef S<S<a, b>, c, d> S2;
在这里S<a,b>
更好地匹配第二个专业。然而,c, d
是第一个特化的剩余参数的更好匹配(单个 arg + 列表 vs 列表)。因此它是 1:1。
如果您在 B
中发表评论在第二个特化中,第二个特化匹配得更好,因为它对第一个参数 (S<...>
) 更特化,其余的同样好。
关于c++ - 模板偏特化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6988489/
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 4 年前。
正如您在 this travis.yml 中看到的那样文件,我的代码依赖于一些第三方库,我在构建项目之前将它们安装在远程系统上。 Travis 每次推送提交时都会下载并构建这些库,这可以避免吗?我的意
我是一名优秀的程序员,十分优秀!