Does in class member initialization takes place at compile time or run-time?

前端 未结 5 1214
醉话见心
醉话见心 2021-02-02 09:42

In C++11 a new feature was introduced where the programmer can initialize class member variables inside class\'s definition, see code below:

struct foo
{ 
  int         


        
5条回答
  •  感动是毒
    2021-02-02 10:23

    Having int size = 3; is exactly equivalent to having int size; and then each constructor that doesn't already have size in its initializer list (including compiler-generated constructors) having size(3) there.

    Strictly speaking C++ doesn't have a distinction between "compile-time" and "run-time".

提交回复
热议问题