in this part of code, I'm trying to read a matrix provided by a question found on the internet, before transforming into a string, fragmenting into smaller elements, and then assign each element of the matrix.
I took information and surely i have a memory leak in the function "convert" or in the previous one "select". I guess I should give a pointer to the string, to something other than NULL.
The problem here is in the concept of scope:
You have i as a member of BestProduct. You use it in the constructor's for loops. When you're done with it, you've left i at 20.
Now the first time that you have used int convert( string mx ); i is still junk from the constructor. It's 20.
So on your first pass, you call string select (0) which returns a string with a size of 2. That gets passed into int convert(string mx). Then when we call mx.substr(i,2) we are calling mx_substr(20,2) which is impossible.
Solutions: use a local int i in the constructor (it's safer). Also, what did you expect i to be in convert? In select you've already extracted a 2-digit string and so I don't think you need to even use substr again.
Try replacing line 48 with this: istringstream assign_mx_a( mx );
In general, try and keep for loop counters local. I like to define them in the for loop itself so that the same letters can be defined elsewhere in the same function with guaranteed integrity. Also, recognize which scope your variables are in. You were treating i,j as if they were global in scope, but they were actually members of bestProduct and locals of main. One good way of keeping track of this is to use m_ as a prefix for all member variables. Another idea is that when in doubt you can prepend the scope to an operator. this->i will ensure that you are using a member variable while ::i would ensure that you are using a global variable. There is no way for you to access local variables from other functions without making them parameters.
By the way, I see a similar problem in void setvalue (int value).
You are using i and j. Members i and j are both 20 as written by the constructor. You never change those. In int main() you define local i,j,k, but those are only locals, you can't expect them to influence the internal members of the bestProduct.
For setvalue, I recommend passing i and j as parameters into the function. Don't rely on global memory and expect it to do what you want. Here's your code with the suggested changes: