Hi, I'm from Taiwan and pretty new to using STL. I would describe the problems I encountered as possible as I could, and hope you guys to give me some advise.
Here, I have three classes. One is the base class of the other two. The following is something about the classses.
Code:class Layer { public: Layer(const string vstrName, const double vdHeight); const string GetName() const; const double GetHeight() const; Layer& operator=(const Layer& rlayer); const bool operator<(const Layer& rlayer) const; const bool operator==(const Layer& rlayer) const; const bool operator!=(const Layer& rlayer) const; protected: string _strName; // name of layer double _dHeight; // height of layer }; class ConLayer: public Layer { public: ConLayer(const string vstrName, const double vdHeight, const doubl const double GetVolt() const; ConLayer& operator=(const ConLayer& rconlayer); private: double _dVolt; // volt of conductor layer }; class InsuLayer: public Layer { public: InsuLayer(const string vstrName, const double vdHeight, const doub const double GetDiel() const; InsuLayer& operator=(const InsuLayer& rinsulayer); private: double _dDiel; // dielectic constant of insulator layer };Then, I use set container to do something I want. Then comes the following.Code://///////////////////////////////////////// // Class Layer member function declariation Layer::Layer(const string vstrName, const double vdHeight): _strName(vstrName), _dHeight(vdHeight) { } const string Layer::GetName() const { return _strName; } const double Layer::GetHeight() const { return _dHeight; } Layer& Layer::operator=(const Layer& rlayer) { _strName = rlayer._strName; _dHeight = rlayer._dHeight; return *this; } const bool Layer::operator<(const Layer& rlayer) const { return this->_strName < rlayer._strName; } const bool Layer::operator==(const Layer& rlayer) const { return this->_strName == rlayer._strName; } const bool Layer::operator!=(const Layer& rlayer) const { return this->_strName != rlayer._strName; } // Class Layer member function declariation /////////////////////////////////////////// ////////////////////////////////////////////// // Class ConLayer member function declariation ConLayer::ConLayer(const string vstrName, const double vdHeight, const double Layer(vstrName, vdHeight), _dVolt(vdVolt) { } const double ConLayer::GetVolt() const { return _dVolt; } ConLayer& ConLayer::operator=(const ConLayer& rconlayer) { Layer::operator=(rconlayer); _dVolt = rconlayer._dVolt; return *this; } // Class ConLayer member function declariation ////////////////////////////////////////////// /////////////////////////////////////////////// // Class InsuLayer member function declariation InsuLayer::InsuLayer(const string vstrName, const double vdHeight, const doubl Layer(vstrName, vdHeight), _dDiel(vdDiel) { } const double InsuLayer::GetDiel() const { return _dDiel; } InsuLayer& InsuLayer::operator=(const InsuLayer& rinsulayer) { Layer::operator=(rinsulayer); _dDiel = rinsulayer._dDiel; return *this; } // Class InsuLayer member function declariation ///////////////////////////////////////////////
I don't have any error or warning in compiling and linking. But I don't get what I expected when ddd (debug tool) is employed. That is, after insert operation, instead of a duplicate object of ConLayer/InsuLayer, I got a object in set with initial values which are set in constructor.Code:string __strLayerName; // name for conductor or insulator layer set<ConLayer> __setConLayer; set<InsuLayer> __setInsuLayer; ///////////////////////////////////////////////// // brief: save the layer name for later use // return: none void set_layer_name(const char* pcharName) { __strLayerName = pcharName; } /////////////////////////////////////////////////////////////////// // brief: create a conductor layer based on given information // return: none void set_con_layer(const double vdHeight, const double vdVolt) { __setConLayer.insert( ConLayer(__strLayerName, vdHeight, vdVolt) ); } /////////////////////////////////////////////////////////////////// // brief: create a insulator layer based on given information // return: none void set_insu_layer(const double vdHeight, const double vdDiel) { __setInsuLayer.insert( InsuLayer(__strLayerName, vdHeight, vdDiel) ); }
I have done much efforts to find what's wrong and got nothing. Could someone give some suggestion? Or some information like website could give me some hints?
Thanks in advance.
David



LinkBack URL
About LinkBacks



I used to be an adventurer like you... then I took an arrow to the knee.