I have my code almost all done, and I get no errors, but I can't get my Timezone to print when I call it. Can anyone point me in the right direction, what am I missing?
Here you have the local variable tz assigned to the local variable tz. You would need to change it to this->tz = tz;. This goes for anywhere where you have a local variable name the same as a class member name.
Thank you very much, it works. What is the NB for? I am curious if there is another way, because the instructor in our live lecture didn't use this-> when making his example. I followed the example of the instructor, and I watched the lecture many times. He didn't continue his example til there was an output screen though.
I can put some more comments in now and divide the program up into different headers and .cpp files.
Given your other accessors, if you'd been consistent with your naming you wouldn't have hit the problem!
hr = hour
min = minute
tz = timezone ???
I rarely see this-> in code at work; it is generally seen as poor style. You only use it when you really have to.
Some people, including me, mark their member variabled with a prefix or suffix. If you do this the problem goes away. And I find it helps me to follow the code.
Where I've worked (all companies) use an m_ prefix to mark all member variable. This comes from of MFC and ATL, which are libraries I've frequently encountered. Other styles are underscore prefixes and suffixes.
Some people reverse the strategy and use (e.g.) an underscore prefix for their parameter names. Less commonly I have seen a p_ prefix used.
Strictly speaking, the convention on underscore prefixes applies to identifiers in the global namespace. And it's _ followed by a capital letter or another _ which are reserved. So _ followed by a lower case letter is ok.
That said, all the coding conventions I've worked under avoid all use of _ prefixes for consistency. But I do bump into examples using _ followed by lower case letters, so other people obviously have a different opinion/habit.
Andy
P.S. Even though the rules is for globals, macros could potentially cause carnage to a poorly named member variables.
17.4.3.1.2 Global names [lib.global.names]
1 Certain sets of names and function signatures are always reserved to the implementation:
— Each name that contains a double underscore (__) or begins with an underscore followed by an upper-case letter (2.11) is reserved to the implementation for any use.
— Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace.