How to instantiate an object using smart pointers

Hello to everyone who I am currently using the QuickFast library, and I saw this ad using smart boost pointers:

namespace QuickFAST{
namespace Messages{
    class FieldIdentity;
    typedef boost::intrusive_ptr<const FieldIdentity> FieldIdentityCPtr;
    typedef boost::intrusive_ptr<FieldIdentity> FieldIdentityPtr;

    void QuickFAST_Export intrusive_ptr_add_ref(const FieldIdentity * ptr);
    void QuickFAST_Export intrusive_ptr_release(const FieldIdentity * ptr);
    void QuickFAST_Export intrusive_ptr_add_ref(FieldIdentity * ptr);
    void QuickFAST_Export intrusive_ptr_release(FieldIdentity * ptr);

    }
}

and I got another class that I need to create, this is the class:

namespace QuickFAST{
namespace Messages{
    /// @brief the representation of a field within a message.
    class QuickFAST_Export MessageField
    {
    public:
    /// @brief Construct from an identity and a typed value.
        MessageField(const FieldIdentityCPtr & identity, const FieldCPtr & field)
            : identity_(identity)
            , field_(field)
            {
            }

    private:
        FieldIdentityCPtr identity_;
        FieldCPtr field_;
    };
    }
}

so my question is: when I need to create a MessageField, I need to first prepare my FieldIdentityCPtr (respectively FieldCPtr), but this is a powerful smart pointer, so correct me if I am wrong, but I thought it might be:

FieldIdentityCPtr identityFF_= new  FieldIdentity(nameFld,,idFld);
FieldCPtr fieldFF_ = new Field(typeFld,false);
MessageField(*identityFF_,*fieldFF_);
+3
source share
1 answer

No , it should be MessageField(identityFF_,fieldFF_);.

, . , MessageField(*identityFF_,*fieldFF_);, FieldIdentityC FieldC , , , . , , .

+1

All Articles