POV-Ray : Newsgroups : povray.programming : OT - need help tracking a (few) bug(s) in my little raytracer (C++) : Re: OT - need help tracking a (few) bug(s) in my little raytracer(C++) Server Time
28 Jul 2024 18:27:30 EDT (-0400)
  Re: OT - need help tracking a (few) bug(s) in my little raytracer(C++)  
From: Vahur Krouverk
Date: 9 Aug 2001 10:15:55
Message: <3B729B7D.10A2592D@aetec.ee>
Scott Hill wrote:
> 
> "Thorsten Froehlich" <tho### [at] trfde> wrote in message
> news:3b71858f@news.povray.org...
> >
> >  I usually write operators like *, /, + outside the class.
> 
>     I've seen this done in many places, but have never understood why -
> these operations are properties of the class and therefore, surely, the
> correct place for them to reside is within the class ?
> 
The reason for this is notation convenience. Consider class Complex with
operators *, /, +, - defined in class scope
class Complex{
  public:
    const Complex operator *(const Complex & c1){
      //...
    }

};
Now you can do this:
Complex c1, c2;
c1=c2*5;
but can't do this:
c1=5*c2;
as there is no operator *(const Complex & c) for type int. If you define
it outside of class:
const Complex operator *(const Complex &c1, const Complex &c2);
and have constructor for Complex, which allows object creation from int,
then second statement compiles OK.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.