push_back到向量

时间:2015-12-07 04:35:43

标签: c++ c pointers boost vector

我正在从另一个boost共享ptr指针创建一个boost共享指针,并将其添加到另一个类中的向量中,如下所示:

boost::shared_ptr<Parcel> parcel; // this is a variable initialized in the constructor when the class is created.

boost::shared_ptr<Parcel> profitableParcel = parcel;
            devModel->addProfitableParcels(profitableParcel);

将指针添加到向量的函数如下:

        void DeveloperModel::addProfitableParcels(boost::shared_ptr<Parcel> profitableParcel)
        {
            {
                boost::mutex::scoped_lock(addParcelLock);
                std::vector<boost::shared_ptr<Parcel> > profitableParcels;
                profitableParcels.push_back(profitableParcel);
            }
        }

我在获取SIGABRT:ABORTED错误(双重释放或损坏(!prev):0x00007fffac0d0c00 ***)当尝试将第二个元素添加到int_free(malloc.c)中的向量时,下面是堆栈跟踪: enter image description here

下面是我得到的另一个堆栈跟踪。 enter image description here

下面是Parcel.cpp的复制构造函数和赋值运算符。似乎在某种程度上,在Parcel类的复制构造函数之前,&#34; source&#34;变量变为null。

 Parcel::Parcel( const Parcel& source)
{
    this->id = source.id;
    this->tazId = source.tazId;
    this->lot_size = source.lot_size;
    this->gpr = source.gpr;
    this->land_use_type_id = source.land_use_type_id;
    this->owner_name = source.owner_name;
    this->owner_category = source.owner_category;
    this->last_transaction_date = source.last_transaction_date;
    this->last_transaction_type_total = source.last_transaction_type_total;
    this->psm_per_gps = source.psm_per_gps;
}

Parcel& Parcel::operator=( const Parcel& source)
{
    this->id = source.id;
    this->tazId = source.tazId;
    this->lot_size = source.lot_size;
    this->gpr = source.gpr;
    this->land_use_type_id = source.land_use_type_id;
    this->owner_name = source.owner_name;
    this->owner_category = source.owner_category;
    this->last_transaction_date = source.last_transaction_date;
    this->last_transaction_type_total = source.last_transaction_type_total;
    this->psm_per_gps = source.psm_per_gps;
    return *this;
}

0 个答案:

没有答案