来自C++标准库的auto_ptr声明
namespace std {
template <class Y> struct auto_ptr_ref {};
template <class X>
class auto_ptr {
public:
typedef X element_type;
// 20.4.5.1 construct/copy/destroy:
explicit auto_ptr(X* p =0) throw();
auto_ptr(auto_ptr&) throw();
template <class Y> auto_ptr(auto_ptr<Y>&) throw();
auto_ptr& operator=(auto_ptr&) throw();
template <class Y> auto_ptr& operator=(auto_ptr<Y>&) throw();
auto_ptr& operator=(auto_ptr_ref<X>) throw();
~auto_ptr() throw();
// 20.4.5.2 members:
X& operator*() const throw();
X* operator->() const throw();
X* get() const throw();
X* release() throw();
void reset(X* p =0) throw();
// 20.4.5.3 conversions:
auto_ptr(auto_ptr_ref<X>) throw();
template <class Y> operator auto_ptr_ref<Y>() throw();
template <class Y> operator auto_ptr<Y>() throw();
};
Run Code Online (Sandbox Code Playgroud)
}
我不明白这部分的目的:
template <class Y> struct auto_ptr_ref {};
Run Code Online (Sandbox Code Playgroud)
在不声明任何变量的情况下,这些变量如何有效:
auto_ptr& operator=(auto_ptr_ref<X>) throw();
Run Code Online (Sandbox Code Playgroud)
这些也是:
auto_ptr(auto_ptr_ref<X>) throw();
template <class Y> operator auto_ptr_ref<Y>() throw();
Run Code Online (Sandbox Code Playgroud)
编辑:还(我只是注意到)我不明白最后两行如何使用"运算符".语法不是"return-type operatoroperand;",返回类型在哪里?操作数?