class Foo {
private:
int m_i;
public:
Foo(int i) : m_i(i) {}
};
class FooA
{
private:
const static Foo & m_foo;
static Foo & m_foo2;
};
Q1> how to initialize const static reference?
Q2> How to initialize non-const static reference?
Note:
You can make changes for class FooA in order to illustrate the methods.
In the same way you initialize non-reference
staticmembers:where
fooObj1andfooObj2are global variables of typeFoo.Note
fooObj1andfooObj2must be initialized beforem_fooandm_foo2, otherwise you might face static initialization order fiasco problem.