Is it safe to call a function to intialize a class in a ctor list?

Posted by Michael Dorgan on Stack Overflow See other posts from Stack Overflow or by Michael Dorgan
Published on 2010-04-21T03:24:40Z Indexed on 2010/04/21 3:33 UTC
Read the original article Hit count: 255

Filed under:
|
|

I have Angle class that I want initialized to a random value. The Angle constructor can accept an int from a random() function. Is it safe to place this call in the ctor list:

foo::foo() : Angle(random(0xFFFF)) {...}

or do I have to do it in the body of the constructor?

foo::foo() { Angle = Angle(random(0xFFFF)); ...}

If it matters, the foo class is derived from another class and does have virtual methods. In addition, no exception handling is allowed in our app.

© Stack Overflow or respective owner

Related posts about c++

Related posts about initialization