c++ - variables not initializing in my constructor -
so problem simple, data initalizing in constructor not saving @ all.
basically have pin pointed 1 point. have constructor in class
strset::strset(std::string s){ std::vector<std::string> strvector; strvector.push_back(s); }
and in main file have
else if(command == "s"){ cout << "declare (to singleton). give set element:"; cin >> input >> single_element; vector_info temp; temp.name = input; strset set(single_element); set.output(); temp.vector = set; list.push_back(temp); }
when constructor called , check length of vector answer appropriate, when check length of vector in output, resets 0?
can me, appreciated!!!!!!!
edit
this .h file
class strset { private: std::vector<std::string> strvector; // empty (when constructed) bool issorted () const; public: strset (); // create empty set strset (std::string s); // create singleton set void nullify (); // make set empty bool isnull () const; int size() const; void output() const; bool ismember (std::string s) const; strset operator + (const strset& rtside); // union strset operator * (const strset& rtside); // intersection strset operator - (const strset& rtside); // set subtraction strset& operator = (const strset& rtside); // assignment }; // end of strset class
looks, class body has strvector, declaring again in constructor, wrong, because compiler referenced new local strvector , not class strvector.
you need change constructor to:
strset::strset(std::string s){ strvector.push_back(s); }
Comments
Post a Comment