Quick Q: Are class member initializers evaluated at compile time?—StackOverflow

Save to:
Instapaper Pocket Readability

Quick A: Maybe.

Recently on SO:

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

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 size = 3;
  int id   = 1;
  int type = 2;
  unsigned char data[3] = {'1', '2', '3'};
};

Is this initialization takes place during compile time or this feature is just syntactic sugar and member variables are initialized in the default constructor?

Add a Comment

You must sign in or register to add a comment.

Comments (0)

There are currently no comments on this entry.