c++ - push_back private vectors with 2 methods, one isn't working -
I have a doubles class with a private vector. To access or modify these values, first I
void classA :: pushVector (double i) {this-> vector.push_back (i); } Double Class A :: Gatevector (Int i) {Return vector [i]; }
It works for a while until I can not get it until I had to overload many operators for it, so I changed it to change Try and set the value instead of vector directly, i.e.
zero square A :: set vector (vector & lt; double & gt; vector) {this- & gt; Vector = vector; } Vector & lt; Double & gt; ClassA :: getVector () {return vector; }
Now, it is said that there is a class B in which there is a private class A element, which obtains and determines how to read and write. The problem was when I tried to return a value to the end vectors in class A.
zero classB :: setFirstValue (double first) {this-> getClassA () GetVector () push_back (first); }
This vector is nothing but it remains unchanged and I do not know why ... any thoughts?
You vector by vector in your getVector () It means that in your call "this-> getclassA (). GetVector (). Push_back (first); ", you copy the vector, then you press the element on the copy, the copy is immediately discarded.
To work as a way to get it, you have to return the vector from context. Your method will look like this:
"vector and square a :: millecator ()"
Comments
Post a Comment