I have these classes:
class A
{
};
class B : public A
{
public:
B(int val);
private:
int* m_int;
};
B::B(int val)
{
m_int = &val;
}
I call the code like so, inside 1 function, i know the vars will be destroyed once they are out of scope, but I only need them in this function:
{
...
int _int = 0;
B obj(_int);
A *obj2 = &obj;
_int++;
...
}
The problem is that _int is changing to 1, but m_int stays the same. I need m_int to reflect what the value in _int is, without the need to update it with code. I thought having a pointer to a memory location would work?
The second problem is that when I hover my mouse over obj2, to see the values of obj, I get the message “children could not be evaluated”.
The pointer
m_intwill stay the same but the value pointed to*m_intwill change, you’ll also have to pass the valuevalby reference to the function.EDIT: Saw your edited question, since this is done from the constructor you can do:
To have
m_intreference the same variable.