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内部定义一个函数做重载,而是通过一个代理类.

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-17
  • 2021-05-27
  • 2021-09-22
  • 2021-11-09
  • 2021-11-13
  • 2021-08-16
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-05
  • 2022-01-06
相关资源
相似解决方案