operator ->重载是怎么做到的?
https://stackoverflow.com/questions/8777845/overloading-member-access-operators-c
struct client
{ int a; };
struct proxy {
client *target;
client *operator->() const
{ return target; }
};
struct proxy2 {
proxy *target;
proxy &operator->() const
{ return * target; }
};
void f() {
client x = { 3 };
proxy y = { & x };
proxy2 z = { & y };
std
并非如普通操作符一样在class内部定义一个函数做重载,而是通过一个代理类.
作者:sdu20112013
如果您觉得阅读本文对您有帮助,请点一下“推荐”按钮,您的“推荐”将是我最大的写作动力!欢迎转载,转载请注明出处.