Is it undefined behavior in the case of the private functions call in the initializer list?

Posted by Alexey Malistov on Stack Overflow See other posts from Stack Overflow or by Alexey Malistov
Published on 2010-03-22T12:58:28Z Indexed on 2010/03/22 13:01 UTC
Read the original article Hit count: 234

Consider the following code:

struct Calc
{
   Calc(const Arg1 & arg1, const Arg2 & arg2, /* */ const ArgN & argn) :
      arg1(arg1), arg2(arg2), /* */ argn(argn), 
      coef1(get_coef1()), coef2(get_coef2()) 
   {
   }

   int Calc1();
   int Calc2();
   int Calc3();

private:
  const Arg1 & arg1;
  const Arg2 & arg2;
  // ...
  const ArgN & argn;

  const int coef1; // I want to use const because 
  const int coef2; //      no modification is needed.

  int get_coef1() const {
     // calc coef1 using arg1, arg2, ..., argn;
     // undefined behavior?     
  }
  int get_coef2() const {
     // calc coef2 using arg1, arg2, ..., argn and coef1;
     // undefined behavior?
  }

};

struct Calc is not completely defined when I call get_coef1 and get_coef2 Is this code valid? Can I get UB?

© Stack Overflow or respective owner

Related posts about c++

Related posts about undefined-behavior