Lets have a class (called Class with capital C)
have a class member data.
But when we declare the class data in the body of the Class,
we have to initialize it with something
(default constructor or other constructor)
however in c++ the initialization used to task to the Class constructor.
But we have to initialze during the declaration before calling the constructor of the main Class.
Practically this means that you have to initialize with some stuffing values before the constructor initialiye it with the right values.
This is not a beauty as far as I understand.
It is possible to do another way?
merse
0
Junior Poster
Recommended Answers
Jump to PostHi!
I not sure that i got it, can you provide a example? I love examples!
Jump to PostThe whole point of a constructor is to initialise any member variables in your class.
If members are not initialised correctly at construction, then you are at risk of inroducing all manner of bugs into your program.So in your example, your default constructor for your mytype class should …
Jump to PostWell, for starters, it's not an ugly solution at all!
It's common sense and good practice! When constructing an object all members should correctly initialised. If you don't know what the value of a member variable is going to be when the class is instantiated, give it a default value. …
All 11 Replies
programmersbook
17
Junior Poster
merse
0
Junior Poster
JasonHippy
739
Practically a Master Poster
merse
0
Junior Poster
JasonHippy
739
Practically a Master Poster
merse
0
Junior Poster
merse
0
Junior Poster
merse
0
Junior Poster
Narue
5,707
Bad Cop
Team Colleague
merse
0
Junior Poster
Narue
5,707
Bad Cop
Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.