| re: method operator+ (try catch)/* Help needed*/
stephane wrote:[color=blue]
> Hi again, I would like to make sure I am right (if I am). This is the last
> time I'll bother you with this code I promise! It's just that I don't have a
> teacher and I have to prepare an exam. I would really be grateful if someone
> could have a quick look at it!
> I had to implement the surcharge of the operator+ and its utilization too.
>
>
> Thoraire Thoraire::operator+(const Thoraire& hor)const throw
> (TenseignantError,Toverflow)[/color]
This operator shouldn't be adding hor to *this, it should be making a
new object which is the result of adding how and *this, and returning
that. I think what you've implemented here is operator+=. While you
don't have to, a guide I've found is the best to follow in almost all
situations is "do the same as int".
Also while you can give throw specifications to functions, most people
(even experts) don't bother. If however your teacher expects them, you
might have to put them in...
[color=blue]
> {
> if(hor.m_nomEnseignant != m_nomEnseignant)
>
> throw TenseignantError();
>
> for(int i=0;i<hor.m_nbCases;i++)
> {
> if(m_nbCases>CcasesMax)
> throw Toverflow();[/color]
You could move this throw outside of the loop perhaps, and check it
before starting? This would have the advantage of not leaving the object
in a broken state when you threw.
Apart from that it appears reasonable to me :)
Chris |