Prototype of a shared_ptr aliasing constructor form g++:
template<typename _Yp>
shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) noexcept
: __shared_ptr<_Tp>(__r, __p) { }
The example given there is:
shared_ptr< pair<int,int> > pii(new pair<int,int>());
shared_ptr<int> pi(pii, &pii->first);
That works; has always worked. But looking at the prototype, _Yp is the template argument that we are providing to instantiate the template and hence last line above feels like it should should read:
shared_ptr<pair> pi(pii, &pii->first);
But definitely the example is correct. So how do we explain this? I looked at the prototype for the first time today and I am trying understand how to interpret it. Thanks for your comments/explanations.
Aucun commentaire:
Enregistrer un commentaire