I have a class member function which is a void function and calculates one of my class variables.
Is there any way to access this class variable?
1 2 3 4 5 6 7 8
class Example {
int answer;
void memfun();
};
void Example::memfun() {
answer = 42;
};
The memfun() is "a class member function which is a void function".
The answer is a "class variable".
The memfun() does "access" the class variableanswer.
The memfun() does modify the class variableanswer.
The thing that the "void function" does "calculate" (42) is stored into class variable by the function.
This statement answer = 42; is an assignment. It assigns a value to variable.
That is what you did ask. How your "void function" should access a member variable.
That is what your function did (for Nrow_ptr_), until you did change the function.
That is what your function did not do for row_ptr_.
You have "a big code". You don't seem to understand any of it, yet you keep adding more. That cannot succeed.
You don't seem to understand what we say, ask, or tell.
@keskiverto first of all I am really grateful for your time and explanations. I really do appreciate that. Please don't interpret my answer as rude But I think there is some misunderstanding here. Maybe I asked my question not in the best way I could, by the way I'm not a software engineer. Otherwise I would be posting answers not questions. I just started object oriented programming around one month ago, and all the code I have I wrote it by myself and I understand what I have written so far. Actually I wrote it before in c and now I'm moving to c++. In the previous comments and answers posted here I was searching for a way to use the class variable set in the void member function outside the void function. And I find a solution just by passing the desired variable by refrence as an argument in the void function. Another way to say, imagine in this void memfun we are setting a vector of vector of double and I need this in other part of code. Anyway I apologize if I've caused you any inconvenience by my question and again thank you for your answers.