c++ 试用 define private public 报错

尝试将private定义成public--报错----redeclared with different access

查阅材料:https://stackoverflow.com/questions/47839718/sstream-redeclared-with-public-access-compiler-error

I wanted to check whether Catch 2.1.0 fixed all perf. regression from Catch Classic on a real world test suite, but using #define private public in test files causes compilation errors because of ODR violations.。 

如果是UT中需要访问私有成员,可以采用下面开源库。

可以通过模板方式错位实现对私有成员的访问 https://github.com/martong/access_private-- The ISO C++ standard specifies that there is no access check in case of explicit template instantiations (C++14 / 14.7.2 para 12).

 

----update 

实际上gcc可以使用-fno-access-control进行单元测试。这样访问控制就失效掉了~~  参考了cpp-stub--https://blog.csdn.net/coolxv_6533/article/details/79550197

 

posted @   dzqabc  阅读(393)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 字符编码:从基础到乱码解决
历史上的今天:
2012-02-16 linux下进程与线程
2012-02-16 解决VC6在win7下打开文件崩溃问题(实际上没有什么用了,只是做个记录,知道没有办法解决)
2012-02-16 pthread_join
2012-02-16 pthread_self
2012-02-16 pthread_create
2012-02-16 Beyond Compare 3 merge script(bc的脚本模板)
2012-02-16 管理处理器的亲和性(affinity)
点击右上角即可分享
微信分享提示