about constructor and class

This is a discussion on about constructor and class within the C++ Programming forums, part of the General Programming Boards category; Hi guys,
I wanted to know that if we are making a program eg.for music items.
Can we write the ...

If your constructor has no user defined code is there any requirement for it? As far as i recall I I have always written a declaration as a matter of course, but i understood that c++ would just initialise everything to binary 0 if no constructor was typed by the coder. As a backward compatability step with C code constructs, Does that still apply in the new standard?

As far as i recall I I have always written a declaration as a matter of course, but i understood that c++ would just initialise everything to binary 0 if no constructor was typed by the coder. As a backward compatability step with C code constructs, Does that still apply in the new standard?

That was never the case, even before C++11. If your class contains members of built-in types or PODs, they won't get initialized to anything unless you make it so by supplying a user-defined constructor in which you explicitly initialize those members.

Will their be any problem if we write the class and its constructor with an underscore?

The only time you would ever have a problem with an underscore in a variable, function name would be if it was a leading underscore. Many of the standard library functions use underscores. See this documentation for std::string and you should notice functions such as c_str(), etc.

The only time you would ever have a problem with an underscore in a variable, function name would be if it was a leading underscore. Many of the standard library functions use underscores. See this documentation for std::string and you should notice functions such as c_str(), etc.

Jim

The standard reserves GLOBAL identifiers with a LEADING underscore for use by compiler vendors. All identifiers with 2 consecutive underscores are also reserved. A single underscore in the middle of an identifier is never a problem.

EDIT: I just reread your post and realized that you never actually implied anything to the effect of the boldened part. Sorry, reading comprehension fail on my part.

The standard reserves GLOBAL identifiers with a LEADING underscore for use by compiler vendors. All identifiers with 2 consecutive underscores are also reserved. A single underscore in the middle of an identifier is never a problem.

And you're telling me this for? As I said the only time you would ever have a problem is when you use a leading underscore. I didn't say when because it doesn't really matter in this context. In my opinion you should avoid using a leading underscore for any variable, I don't care where you use it I consider using a leading underscore a bad practice.

That was never the case, even before C++11. If your class contains members of built-in types or PODs, they won't get initialized to anything unless you make it so by supplying a user-defined constructor in which you explicitly initialize those members.

Ok so forget the initialisation, although that has been written in published books - no guarantee i know, but regardless, I mean the fact you can / could instansiate an object without writing a constructor declaration in the class declaration