c++ - unable to change member value with method -


i have int member named size within blob class value attempting change within method. initially, tried...

void blob::make_union(blob parent_blob){     parent=&parent_blob;     parent_blob.size = parent_size } 

then tried making function sole purpose change size value. worth noting changes values within function verified cout statements.

int blob::change_size(int dat_size){     size=size+dat_size;     return this.size; } 

after making new method change other method

'void blob::make_union(blob parent_blob){     parent=&parent_blob;     int temp = size;     parent_blob.size = parent_blob.change_size(temp); }' 

still no dice. following within main function work.

if (charmatrix[m-1][n-1]==charmatrix[m][n]){ blobmatrix[m][n].make_union(blobmatrix[m-1][n-1]); blobmatrix[m-1][n-1].size=blobmatrix[m-1][n-1].size + blobmatrix[m][n].size;

what doing wrong?

you passing blob class value: making copy of blob object, , function change_size working with.

void increment_number(int i) { ++i; } void increment_number_ref(int& i) { ++i; }  int main() {     int n = 6;     // takes copy of number, , increments number, not 1 passed in!     increment_number(n);     // n == 6     // passed our object reference. no copy made, function works correct object.     increment_number_ref(n);     // n == 7     return 0; } 

you need pass blob reference (or pointer) if wish modify object's value: see above.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -