cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
Correct initialization of a class
Correct initialization of a class
Apr 7, 2016 at 11:03pm UTC
leonid1990
(41)
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
Apr 7, 2016 at 11:07pm UTC
Apr 7, 2016 at 11:16pm UTC
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!
Apr 8, 2016 at 12:15am UTC
leonid1990
(41)
Interesting very much. Thank you!
Topic archived. No new replies allowed.