Correct initialization of a class

Hello,
I know that CTOR can be used for assigning default values to fields. But anyway - is it correct to initialize fields of a class in the way below, or do I have to use always the CTOR for this purpose? When is it necessary to use only the CTOR?

1
2
3
4
5
6
class A
{
public:
    int num1 = 1;
    int num2 = 2;
};
Last edited on
closed account (E0p9LyTq)
C++11 added the ability to initialize class data members that way.

http://www.informit.com/articles/article.aspx?p=1852519

I would have said it wasn't allowed until I started looking, and I find out I was wrong. Ooops!
Interesting very much. Thank you!
Topic archived. No new replies allowed.