当前位置: 首页 > news >正文

stl模板库成员函数重载类型混肴编译不通过解决方法

stl模板库成员函数重载类型混肴编译不通过解决方法
这种方式编译不通过IsArithmetic和HasMemberList编译器存在混肴

template <typename T, typename Enable = std::enable_if<IsArithmetic<T>::value>::type >static void DumpWrapper(T* filed, std::string fieldname){printf("fieldname:=>%s\r\n", fieldname.c_str());enum : std::size_t { IntValSize = sizeof(T) };if (IntValSize > 4){printf("%s:=>%016llx\r\n", fieldname.c_str(), *filed);}else{printf("%s:=>%08x\r\n", fieldname.c_str(), *filed);}}template <typename T, typename  Enable = std::enable_if<IsArithmetic<T>::value >::type  >static void DumpWrapper(T filed, std::string fieldname){printf("fieldname:=>%s\r\n", fieldname.c_str());enum : std::size_t { IntValSize = sizeof(T) };if (IntValSize > 4){printf("%s:=>%016llx\r\n", fieldname.c_str(), filed);}else{printf("%s:=>%08x\r\n", fieldname.c_str(), filed);}}template <typename T, typename Enable = EnableIfHasMemberList<T>>static void DumpWrapper(nop::S7PlusPacketValue<T>* filed, std::string fieldname){printf("fieldname:=>%s\r\n", fieldname.c_str());filed.Dump();}template <typename T, typename Enable = EnableIfHasMemberList<T>>static void DumpWrapper(nop::S7PlusPacketValue<T> filed, std::string fieldname){printf("fieldname:=>%s\r\n", fieldname.c_str());filed->Dump();}

解决方法必须明确重载IsArithmetic和HasMemberList编译器存在混肴,加上双重判断typename Enable = std::enable_if<IsArithmetic::value&!HasMemberList::value>::type来明确混肴条件,这种方式编译通过

template <typename T, typename Enable = std::enable_if<IsArithmetic<T>::value&!HasMemberList<T>::value>::type >static void DumpWrapper(T* filed, std::string fieldname){printf("fieldname:=>%s\r\n", fieldname.c_str());enum : std::size_t { IntValSize = sizeof(T) };if (IntValSize > 4){printf("%s:=>%016llx\r\n", fieldname.c_str(), *filed);}else{printf("%s:=>%08x\r\n", fieldname.c_str(), *filed);}}template <typename T, typename  Enable = std::enable_if<IsArithmetic<T>::value & !HasMemberList<T>::value>::type  >static void DumpWrapper(T filed, std::string fieldname){printf("fieldname:=>%s\r\n", fieldname.c_str());enum : std::size_t { IntValSize = sizeof(T) };if (IntValSize > 4){printf("%s:=>%016llx\r\n", fieldname.c_str(), filed);}else{printf("%s:=>%08x\r\n", fieldname.c_str(), filed);}}template <typename T, typename Enable = EnableIfHasMemberList<T>>static void DumpWrapper(nop::S7PlusPacketValue<T>* filed, std::string fieldname){printf("fieldname:=>%s\r\n", fieldname.c_str());filed.Dump();}template <typename T, typename Enable = EnableIfHasMemberList<T>>static void DumpWrapper(nop::S7PlusPacketValue<T> filed, std::string fieldname){printf("fieldname:=>%s\r\n", fieldname.c_str());filed->Dump();}
http://www.lryc.cn/news/260568.html

相关文章:

  • MySQL——表的约束
  • cordic 算法学习记录
  • 【STM32】电机驱动
  • csp 如此编码 C语言(回归唠嗑版)
  • 或许是全网最全的延迟队列
  • C语言结构体小项目之通讯录代码实现+代码分析
  • tp5 rewrite nginx重写
  • .NET 反射优化的经验分享
  • 使用opencv的Sobel算子实现图像边缘检测
  • 亿欧网首届“元创·灵镜”科技艺术节精彩纷呈,实在智能AI Agent智能体展现硬核科技图景
  • 宝塔面板快速搭建本地网站结合内网穿透实现远程访问【无需公网IP】
  • css的Grid布局
  • Python接口测试框架选择之pytest+yaml+Allure!
  • 03-详解Nacos注册中心的配置步骤和功能
  • 微服务学习:Nacos微服务架构中的服务注册、服务发现和动态配置Nacos下载
  • 逆向经历回顾总结
  • 企业IT安全:内部威胁检测和缓解
  • Linux 服务器较为强大的运维及管理脚本实现(支援:本机线上操作)
  • 【数据结构】插入排序,希尔排序,选择排序,堆排序,冒泡排序
  • MyBatis--07--启动过程分析、SqlSession安全问题、拦截器
  • Qt基础之四十二:QMap、QHash的实现原理和性能对比
  • 虚幻学习笔记12—C++类的实例化
  • 【《漫画算法》笔记】快速排序
  • C++如何通过调用ffmpeg接口对H265文件进行编码和解码
  • 8位LED流水灯设计
  • eclipse连接mysql数据库(下载eclipse,下载安装mysql,下载mysql驱动)
  • 【信息学奥赛】拼在起跑线上,想入道就别落下自己!
  • Python 进程池Pool Queue,运行不出来结果!
  • yolov8实战第二天——yolov8训练结果分析(保姆式解读)
  • ​urllib.request --- 用于打开 URL 的可扩展库​