Modifing a class instance from the class itself.

How can i modify a specific instance of a class using a function in the class itself?

What i mean:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
    class CLASS
    {
    private:
    int i;

    public:
    void changeI(int newI);
    void ChangeI_b(CLASS a,int newI);
    
    }

    CLASS a,b;
    a.changeI(2);
    a.changeI_b(b,a.i);


Any way i can do something like this so that after i do a.changeI_b(...) b.i would be equal to 2?
ChangeI_b takes a copy of passed argument, so no modification would be visible outside.
Pass parameter by reference. (And BTW, you do not need newI parameter there as you can replicate it by simply callinng changeI on object b)
1
2
3
4
void ChangeI_b(CLASS& a)
{
    a.i = this->i;
}
Thank you so much!
I tried something like that but i used CLASS* a instead of CLASS& a :/ .
Thx again!
Topic archived. No new replies allowed.