#include <iostream>
    using namespace std;
    class B{
    public:
        int x;
        void setx(int a){
            x =a;
            cout<<"Inside set "<<x<<endl;
        }
        void show();
    };
    void B::show(){
        cout<<"inside show "<<x<<endl;
    }
    class A{
    public:
        void func();
        void func2();
        B bb;
    };
    void A::func(){
        bb.setx(100);
        bb.show();
    }
    void A::func2(){
        bb.show();
    }
    int main()
    {
       A a;
       B b;
       a.func(); 
       b.show(); 
       a.func2(); 
       return 0;
    }
Changes are applicable only to class A, where actual value in class B is not changing. I tried static but its showing error.
OUTPUT I'M GETTING : Inside set 100 inside show 100 inside show 0 inside show 100
OUTPUT I WANT : Inside set 100 inside show 100 inside show 100 inside show 100
 
     
    