Is the output is determined? Here is the code snippet:
#include <iostream>
class Outer {
public:
class Inner {
public:
Inner() {}
void func(Outer& outer) ;
static const int thrd;
};
private:
static const int num;
int var;
};
void Outer::Inner::func(Outer& outer) {
outer.var = 1;
}
const int Outer::Inner::thrd = Outer::num;
const int Outer::num = 5;
int main(){
std::cout << "Outer::Inner::thrd=" << Outer::Inner::thrd << std::endl; //is the output is determined?
}
Avoid static (global) variables. You might run into the static initialization order fiasco at some point when you want to do this kind of things across multiple translation units.
So use
constexprwhenever you can. That way you cannot initialize constants the wrong way. (in header files replace static constexpr, with inline constexpr)