In the project I am working I saw a code like below in code review process:
class A
{
shared_ptr<B> instanceB;
}
A::A ()
{
instanceB = make_shared<B>();
static C localVariable(instanceB.get());
}
I know static variable's are like globals and will be created when program starts and instanceB will be created when A instantiated. And this may crash.
While explaining that I begin to think about what value instanceB.get() would return. Most probably garbage right? And when I think more about it I believe this code even shouldn't be compiled why static variables are allowed to take non-static parameters in their ctors?