I am asking this question for the discussion.
Suppose i have flowing class hierarchy
class A
{
public:
static int varr;
}
class B : public A
{
}
Class C : public A
{
}
If I create the Object of B b1,b2,b3; and C c1,c2,c3; and A a1, a2;
1.will varr is shared across all the object mentioned above or there will be separate instance for different object?
2.if b1 object change the value it will be reflected for c1 object or not.
Yes, it will be shared accross all the instance of all derived(B,C) and base class(A)..
Only one instance for a static object will be created, and at all place that object will be refered. So if you change at one place it means change will be reflected at all location where its being refered.