zoukankan      html  css  js  c++  java
  • 一个auto_ptr的问题

    发信人: Mobem (Waiting...), 信区: CPlusPlus
    标  题: 问一个auto_ptr的问题
    发信站: 水木社区 (Tue Nov  6 11:45:18 2007), 站内

    class A
    {
        protected:
            int a;
        public:
            A(int n){a = n;}
            void f(){std::cout<<"f is invoked!"<<'\n';}
    };

    int main(int argc, char *argv[])
    {   
        A* pp = new A(4);
        std::auto_ptr<A> p(pp);
        p->f();
        p.operator->()->f();
        return 0;
    }
    程序执行时p->f()和p.operator->()->f()的结果一样,看了auto_ptr模板类的实现,发现其中对->操作符的定义如下:
      _Tp* operator->() const __STL_NOTHROW {
        return _M_ptr;
      }
    不理解的是p->f()这个调用是如何做到的?难道在调用时做了p到p.opertaor->()的隐式转换?但在auto_ptr模板类的定义中没有看到opertor _TP*()的定义啊。
    --
    x->m
    x.operator->()->m
    x.operator->().operator->()->m
    ..
    you are right
    【 在 devilphoenix (初號機·神·小白) 的大作中提到: 】
    : An expression x->m is interpreted as (x.operator->())->m for a class object x of type T if T::operator->() exists and if the operator is selected as the best match function by the overload resolution mechanism (13.3).
    : 没看懂你是啥意思
    http://www.newsmth.net/bbstcon.php?board=CPlusPlus&gid=204956

  • 相关阅读:
    linux kgdb 补丁
    linux kdb 内核调试器
    linux 使用 gdb
    linux 系统挂起
    linux oops 消息
    linux strace 命令
    linux ioctl 方法
    linux seq_file 接口
    [数据结构] 迷宫问题(栈和队列,深搜和广搜)
    简化浏览器地址栏訪问路径
  • 原文地址:https://www.cnblogs.com/cutepig/p/951474.html
Copyright © 2011-2022 走看看