c++ - initialized pointers are not passed through constructor -
i have 2 classes server
, broker
. server
member in broker
, of members initialized when broker
members initialized. simple if @ constructors , members:
#include <boost/thread/condition_variable.hpp> class server { private: boost::shared_ptr<boost::mutex> broker_client_mutex;//will initialized in constructor boost::shared_ptr<boost::condition_variable> broker_client_register;//will initialized in constructor public: server(boost::shared_ptr<boost::mutex> broker_client_mutex_, boost::shared_ptr<boost::condition_variable> broker_client_register_) : broker_client_mutex(broker_client_mutex_), broker_client_register(broker_client_register_) {//some log std::cout << "1.server starting mutexes:\n" "broker_client_mutex_[" << broker_client_mutex << "]\n" "broker_client_register[" << broker_client_register << "]" << std::endl; } //... } class broker { private: boost::shared_ptr<boost::mutex> broker_client_mutex; //member passed boost::shared_ptr<boost::condition_variable> client_register;//member passed server server_;//member initialized public: broker(): broker_client_mutex(new boost::mutex)//initialize ,client_register(new boost::condition_variable)//initialize ,server_(broker_client_mutex,client_register)//pass {//some log std::cout << "broker starting mutexes:\n" "broker_client_mutex_[" << broker_client_mutex << "] \n" "broker_client_register[" << client_register << "]" << std::endl; } }
but logs server
arguments passed before initialized:
1.server starting mutexes: broker_client_mutex_[0] broker_client_register[0] broker starting mutexes: broker_client_mutex_[0x1a14a60] broker_client_register[0x1a14620]
why happening , how solve issue ?
update when changed code compilable readers, members initialized expected. difficult show how broker
created coz subclass of agent class. still don't know going wrong !
Comments
Post a Comment