[cairo] cairomm RefPtr problem

Umberto Allievi uallievi at iol.it
Tue Sep 26 23:50:31 PDT 2006


Hello everybody,

	I think I have discovered a problem with cast_static (and cast_dynamic,
cast_const) member function of the RefPtr<> template class.

The original code gives me two errors error: 'int*
Cairo::RefPtr<Caito::Context>::pCppRefcount_' is private

I think the problem is that the original code:

template <class T_CppObject>
  template <class T_CastFrom>
inline
RefPtr<T_CppObject> RefPtr<T_CppObject>::cast_static(const RefPtr<T_CastFrom>& src)
{
  T_CppObject *const pCppObject = static_cast<T_CppObject*>(src.operator->());

  if(pCppObject && src.pCppRefcount_)
    ++(*(src.pCppRefcount_));

  return RefPtr<T_CppObject>(pCppObject); //TODO: Does an unnecessary extra reference() on the C object.
}

is wrong. I think it should be:

template <class T_CppObject>
  template <class T_CastFrom>
inline
RefPtr<T_CppObject> RefPtr<T_CppObject>::cast_static(const RefPtr<T_CastFrom>& src)
{
  T_CppObject *const pCppObject = static_cast<T_CppObject*>(src.operator->());

  if(pCppObject && src.refcount_()) // pCppRefcount_ substituted with refcount_()
    ++(*(src.refcount_()));         // idem

  return RefPtr<T_CppObject>(pCppObject); //TODO: Does an unnecessary extra reference() on the C object.
}

And in fact this version works perfectly (the same for cast_dynamic and cast_const).

	Thanks in advance, Umberto Allievi






More information about the cairo mailing list