智能指针shared_ptr和proto的嵌套message

class S_statics_log2 : public FeatureOperator<::std::string&, const  ::std::shared_ptr<const ::google::protobuf::Message*>&, const int32_t&> {
public:
    virtual int32_t generate(::std::string& dest, const ::std::shared_ptr<const ::google::protobuf::Message*>& feature, const int32_t& scene) override {
        dest.resize(16);
        ::std::cout << "test scene" << ":" << scene<< ::std::endl;
        if (1300==scene){
            ::std::cout << "test (1300==scene)" << ":" << scene<< ::std::endl;
        }
        const ::liu::kai::recommend_item::videoItemFeature* detail_feature = (const ::liu::kai::recommend_item::videoItemFeature*)*feature.get();

        //std::cout << "request:" << (*item_feature.get())->SerializeAsString()<< std::endl;
        ::std::cout << "test detail_feature id:"<< detail_feature->id() << ::std::endl;

        const ::liu::kai::recommend_item::videoItemTagFeaturePool pool = detail_feature->shortvideorecoxyimmer();
        const ::liu::kai::recommend_item::videoItemTagFeature feature_tag = item_feature_pool.alldaydata();
        ::std::cout << "test step 1" << ":" << scene<< ::std::endl;
        uint64_t exposure_num = feature_tag.exposure_num();
        dest.resize(sprintf(&dest[0], "%" PRIu64, exposure_num));
        return 0;

    }
};

1、智能指针  

  shared_ptr<T> p; //空智能指针,可指向类型是T的对象

 if(p) //如果p指向一个对象,则是true

 (*p);//解引用获取指针所指向的对象  p -> number == (*p).number;
 p.get(); //返回p中保存的指针
上一篇:C++新特性 shared_ptr与weak_ptr


下一篇:浅谈分布式锁