2

boost::bind处理boost::shared_ptr方式与原始指针相同。

QObject * object(new QObject);
boost::shared_ptr<QObject> sharedObject(new QObject);

bind(&QObject::setObjectName, object, _1)( "name" );
bind(&QObject::setObjectName, sharedObject, _1)( "name" );

我希望有一个作为原始指针指针boost::bind处理的。QPointers

QPointer<QObject> guardedObject(new QObject);    
// i want to write it like this
bind(&QObject::setObjectName, guardedObject, _1)( "name" );
//now i have to do it like this
bind(&QObject::setObjectName, bind(&QPointer<QObject>::data, guardedObject), _1)( "name" );

有没有人专攻的QPointer

如果不知道从哪里开始或需要专业化什么,那么我可以自己做。

4

1 回答 1

5

添加这个get_pointer函数的重载应该可以解决问题:

namespace boost {
    template<typename T> T * get_pointer(QPointer<T> const& p)
    {
        return p;
    }
}
于 2009-06-11T14:26:47.680 回答