contructor vs inline initialization

what is the difference between
1
2
3
4
template<class T>
stuct S {
    T x = value;
};

and
1
2
3
4
template<class T>
stuct S {
    T x{ value };
};

and
1
2
3
4
5
template<class T>
stuct S {
    T x;
    S() :x(value) {}
};


how does the compiler handle these 3 situations
Last edited on
as Core Guidelines put it,
C.48: Prefer in-class initializers to member initializers in constructors for constant initializers
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rc-in-class-initializer

(the first two are the "in-class initializers"

and choosing between the two,
ES.23: Prefer the {}-initializer syntax https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es23-prefer-the--initializer-syntax
Topic archived. No new replies allowed.