|
看到auto_ptr里面的声明是这样的:
X* operator->() const;
Returns the underlying pointer.
有点不能理解,有这样一段代码
- //
- // auto_ptr.cpp
- //
- #include <iostream.h>
- #include <memory>
- //
- // A simple structure.
- //
- struct X
- {
- X (int i = 0) : m_i(i) { }
- int get() const { return m_i; }
- int m_i;
- };
- int main ()
- {
- //
- // b will hold a pointer to an X.
- //
- auto_ptr<X> b(new X(12345));
- //
- // a will now be the owner of the underlying pointer.
- //
- auto_ptr<X> a = b;
- //
- // Output the value contained by the underlying pointer.
- //
- cout << a->get() << endl;
- //
- // The pointer will be deleted when a is destroyed on
- // leaving scope.
- //
- return 0;
- }
复制代码
在这里按照声明"a->"应该是返回一个X*,那么它怎么能直接就跟get()呢,而不能使用->get()? |
|