title: How to initialize static constant member using function
body: <p>In a very simplified case, I have the following setup in which, I simply want to initialize a constant static member(of class foo) from functions of class A (singleton and instance are unrelated to this question):</p>
  
  <pre><code>class A
  {
  public:
  
      static A instance;
      A &amp; getInstance() { return instance; }
      int i(){ return 10;}
      int j(){ return 20;}
  };
  
  class foo {
  public:
  
      static const int ii = A::getInstance().i() * A::getInstance().j(); 
  };
  const int foo::ii;
  
  int main()
  {
      foo f;
      return 1;
  }
  </code></pre>
  
  <p>the aim is to initialize member ii using some function as above. but it generates the following error:</p>
  
  <pre><code>$ c++ static_constant.cpp 
  static_constant.cpp:14:30: error: ‘A::getInstance()’ cannot appear in a constant-expression
  static_constant.cpp:14:42: error: a function call cannot appear in a constant-expression
  static_constant.cpp:14:44: error: ‘.’ cannot appear in a constant-expression
  static_constant.cpp:14:46: error: a function call cannot appear in a constant-expression
  static_constant.cpp:14:53: error: ‘A::getInstance()’ cannot appear in a constant-expression
  static_constant.cpp:14:65: error: a function call cannot appear in a constant-expression
  static_constant.cpp:14:67: error: ‘.’ cannot appear in a constant-expression
  static_constant.cpp:14:69: error: a function call cannot appear in a constant-expression
  </code></pre>
  
  <p>could you please help me out? will Appreciate it.</p>