c++ - 当且仅当它不会导致重新定义错误时,如何定义新的函数/结构/类?
问题描述
我正在生成 c++ 代码,当且仅当它不会导致重新定义错误时,我才需要定义一个新的函数/结构/类。我怎样才能做到这一点?我认为解决方案是尝试重新定义新的函数/结构/类并使其以 SFINAE 友好的方式失败,但我不知道如何做到这一点。
例如:
int foo (int x, int y) {
return x + y;
}
int foo (int z, int a) { // Obvious redefinition here, how can I make it fail in a SFINAE friendly way?
return x * y;
}
template <typename T, typename U>
struct bar {};
template <typename T, typename U> // Partial template specialisation does not actually specialise the parent template, how do I make this definition fail in a SFINAE friendly way?
struct bar<T, U> {};
解决方案
推荐阅读
- angular - ngx-extended-pdf-viewer 打印页面仅显示要打印的 pdf 的最后一页
- wordpress - 是否可以根据 Woocommerce 上的重量为产品设置定价?
- postgresql - 创建扩展 postgis 给出错误:无法打开扩展控制文件“/opt/pgpro/std-11/share/extension/postgis.control”
- android - 无法在android studio中打开运行窗口
- salesforce - CPQ报价线显示多次
- inkcanvas - 手写功能就像 fiinote 手写一样
- android - 在本机反应中发布后崩溃的应用程序?
- flutter - 如何限制 TextSpan 小部件的文本长度
- javascript - 单击“Enter”按钮时提交表单,并进行验证
- flutter - 如何在不改变屏幕/页面的情况下传递数据?