当前位置:网站首页>Accessing private members using templates
Accessing private members using templates
2022-04-23 18:52:00 【Brick Porter】
#include <iostream>
class B {
int aa = 0,bb=3;
int a=10;
public:
void print()
{
std::cout << "a=" << a << std::endl;
}
};
typedef int B::* stolen_mem_ptr;
template<stolen_mem_ptr MemPtr>
class Robber {
friend stolen_mem_ptr steal() {
return MemPtr;
}
};
template class Robber<&B::a>;
stolen_mem_ptr steal();
int main()
{
B b;
b.print();
auto accessor = steal();
b.*accessor = 100;
b.print();
std::cout << "Hello World!\n";
}
版权声明
本文为[Brick Porter]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210603257607.html
边栏推荐
- Nacos as service registry
- Sentinel服务熔断实战(sentinel整合ribbon+openFeign+fallback)
- 【数学建模】—— 层次分析法(AHP)
- Machine learning theory (7): kernel function kernels -- a way to help SVM realize nonlinear decision boundary
- 中金财富怎么样?在上边开户安全吗
- Résolution: cnpm: impossible de charger le fichier... Cnpm. PS1 parce que l'exécution de scripts est désactivée sur ce système
- : app: transformclasseswithrobustfordevrease meituan hot repair compilation error record
- 12 examples to consolidate promise Foundation
- Halo open source project learning (VII): caching mechanism
- QT curve / oscilloscope customplot control
猜你喜欢
机器学习实战 -朴素贝叶斯
Teach you to quickly rename folder names in a few simple steps
从技术体系到商业洞察,中小研发团队架构实践之收尾篇
【科普】CRC校验(一)什么是CRC校验?
解决:cnpm : 無法加載文件 ...\cnpm.ps1,因為在此系統上禁止運行脚本
Simple use of navigation in jetpack
机器学习理论之(7):核函数 Kernels —— 一种帮助 SVM 实现非线性化决策边界的方式
Use bitnami / PostgreSQL repmgr image to quickly set up PostgreSQL ha
Practice of Druid SQL and security in meituan review
One of the reasons why the WebView web page cannot be opened (and some WebView problem records encountered by myself)
随机推荐
Seata handles distributed transactions
Methods of nested recycleview to solve sliding conflict and incomplete item display
Get a list of recent apps
Click the input box to pop up the keyboard layout and move up
Use of content provider
: app: transformclasseswithrobustfordevrease meituan hot repair compilation error record
程序员如何快速开发高质量的代码?
Summary of actual business optimization scheme - main directory - continuous update
机器学习实战 -朴素贝叶斯
Use bitnami / PostgreSQL repmgr image to quickly set up PostgreSQL ha
MVVM模型
With the use of qchart, the final UI interface can be realized. The control of qweight can be added and promoted to a user-defined class. Only the class needs to be promoted to realize the coordinate
Golang 语言实现TCP UDP通信
Machine learning theory (7): kernel function kernels -- a way to help SVM realize nonlinear decision boundary
[popular science] CRC verification (I) what is CRC verification?
STM32: LCD显示
Chondroitin sulfate in vitreous
Coolweather is revised and connected to the wind weather interface to realize the broken line diagram of temperature
K210 serial communication
WebView opens H5 video and displays gray background or black triangle button. Problem solved