Question: Technically couldn't a programmer overload the + operator to do subtraction.
One minute response: Absolutely; that's one of the arguments against providing operator overloading in a language. But, even if you skip the obviously bad overloads, implementing a good set of operator overloads is a subtle problem.
Question: No questions at this time.
Question: Can you put all definitions in the .h as well as declarations.
One minute response: Yes, although generally it's considered poor programming practice to do that, for the reasons discussed in class. However, sometimes your forced to do just that, as when you're using template functions and classes.
Question: What type of behavior would result from time + 0?
One minute response: It depends on how you define the plus operator for time and integers. It seems sensible to treat the integer as some number of seconds (say) and advance the time by the given number of seconds. Other interpretations are possible too, limited only by your imagination.
Question: { }.
Question: More about classes.
One minute response: Stick around; we'll be talking about them all semester.
Question: I'm o.k.
Question: Can you overload an operator several times in a class: i.e. both a time + time and int + time?
One minute response: Yes. As long as the new signature is distinguishable from all existing signatures, the overload is allowed (the rules are a bit more complex than that, but you get the idea).
Question: Should w expect the STL to operate the same on different implementations, i.e. g++ and cc?
One minute response: For the most part, yes. Because the STL was designed from scratch, there was no need to maintain backwards compatibility with existing implementations, and all behaviors could be specified with a fair degree of rigor. However, the standard gives significant leeway to implementers over implementation details, and what is considered undefined behavior.
Question: Is there a limit as to operator overloading functionality, when does it become cumbersome to implement.
One minute response: Operator overloading is well-enough understood that designing and implementing it is not a significant problem (which is not to say it isn't more work). More of a problem is programmers abusing it, such as defining + to have weird behaviors.
Question: With no code review, how do we find problems with our code that we have overlooked?
One minute response: Testing. Test your code, or - even better - get someone you trust to test your code (and you reciprocate). Also look at your code. Are there some places that are more complicated than others? The complicated parts are good hiding places for errors. What can you do to simplify your code?
Question: How to work with string classes?
One minute response: Get a copy of the string class documentation to know what's available, and then use them.
Question: What are some reasons for not allowing overloading in programming languages?
One minute response: If you carefully design overloading into the language from the start, there aren't any good technical reasons. If, however, you try to shoehorn overloading into an existing language, there's all kinds sticky technical issues that can come up, as illustrated by C++.
Question: Would you say that in-line code is generally bad?
One minute response: Yes. It can cause code bloat of not used carefully, which could end up causing your program to run slower. Using it carefully can be a pain too, because it requires guessing and testing to make sure it's really helping.
This page last modified on 16 July 2003.