boost - c++ Bridge pattern and smart pointer -
i use bridge 1 class, , life create std::vector of std::vector of bridge.
whilst vector of bridge working.
for example :
std::vector<bridge> lbridge(5)
the vector of vector not working. example :
std::vector<std::vector<bridge>> lbridge(5,std::vector<bridge>(4))
when create vector of vector, goes constructor bridge(const bridge & original), , original null...
this code :
bridge.h
#ifndef bridge_h #define bridge_h #pragma once #include <myobject.h> #include <boost/make_shared.hpp> class bridge{ public : bridge(const bridge & original); bridge(const myobject & innerobject); bridge(){}; bridge& operator=(const ibridge& original); private : boost::shared_ptr<myobject> mmyobjectptr; }; #endif
bridge.cpp
#include<bridge.h> bridge::bridge(constbridge& inoriginal){ mmyobjectptr = inoriginal.mmyobjectptr->clone(); } bridge::bridge(const myobject& ininnerobject){ mmyobjectptr = ininnerobject.clone(); } bridge& bridge::operator=(const bridge& inoriginal){ if (this != &inoriginal){ mmyobjectptr = inoriginal.mmyobjectptr->clone(); } return *this; }
you've failed "not working" means expected happen.
my best guess absolutely, positively, want of bridges default initialized, rather you've written, copy vector of bridges each entry of vector-of-vectors.
to this, you'll have make vector of empty vectors, , resize each of individual vectors. or alternatively, create empty vector of vectors, emplace_back
individual vectors 1 @ time.
Comments
Post a Comment