Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
353 views
in Technique[技术] by (71.8m points)

c++ - Has "In class member initialization" feature made into C++11?

In class initialization feature, which allows to initialize normal members inside the class itself,

struct A {
  int a = 0; // error: ISO C++ forbids in-class initialization of non-const static member ‘a’
};

This is giving error in latest compiler gcc-4.6 (with -std=c++0x). Has this feature made into the C++11 standard or gcc still doesn't support it ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Yes, that is legal in C++0x. There is an example of this at N3290 §12.6.2/8:

struct C {
    /* ... */
    int j = 5; // OK: j has the value 5
};

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...