B
baumann@pan
hi all,
i couldn't understand why code 1) can solve the problem of code 2) has.
code 1)
template<class T> T* clone(const T* tp)
{
return tp->clone();
}
and change our make_unique member to call it
template<class T>
void Ptr<T>::make_unique()
{
if (*refptr != 1) {
--*refptr;
refptr = new size_t(1);
p = p ? clone(p): 0; // call the global (not member) version
of clone
}
}
code 2)
template<class T>
void Ptr<T>::make_unique()
{
if (*refptr != 1) {
--*refptr;
refptr = new size_t(1);
p = p ? p->clone() : 0; // here is the problem
}
}
template<class T> T* clone(const T* tp)
{
return tp->clone();
}
i think tp-clone() would has the same sematics of p->clone() since both
p and tp are of same type.
so I couldn't understand the difference. how it can solve the problem
of calls undefined member function?
thanks in advance.
baumann@pan
i couldn't understand why code 1) can solve the problem of code 2) has.
code 1)
template<class T> T* clone(const T* tp)
{
return tp->clone();
}
and change our make_unique member to call it
template<class T>
void Ptr<T>::make_unique()
{
if (*refptr != 1) {
--*refptr;
refptr = new size_t(1);
p = p ? clone(p): 0; // call the global (not member) version
of clone
}
}
code 2)
template<class T>
void Ptr<T>::make_unique()
{
if (*refptr != 1) {
--*refptr;
refptr = new size_t(1);
p = p ? p->clone() : 0; // here is the problem
}
}
vector<char>. Unfortunately, no such function exists!Look at the call to p->clone. Because we are using a Ptr said:, this call will try to call the clone function that is a member of
template<class T> T* clone(const T* tp)
{
return tp->clone();
}
i think tp-clone() would has the same sematics of p->clone() since both
p and tp are of same type.
so I couldn't understand the difference. how it can solve the problem
of calls undefined member function?
thanks in advance.
baumann@pan