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 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 Post>What is the timeline for the compiler?
>If i create an object myclass myobj(...)
>the first is the myclass constructor call,
>or the myclass data member declaration?
The constructor is a magic function. You can think of it like this:class foo { int x; public: foo() …
Jump to Post>i have to write the constructor like this
Yup. On the plus side, this restriction can encourage moderation in template use. ;)>and I have to put spaces between > >
Yea, that's a wart in the syntax that should be fixed in the next revision of the …
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.