a little bit offtopic: c++ question in kdevelop-tutorial
Richard Moore
rich at ipso-facto.freeserve.co.uk
Thu Feb 24 21:18:12 GMT 2000
AndiX33 at aol.com wrote:
>
> hello,
>
> while reading the tutorials shipped with kdevekop, i´ve read an example i
> don´t understand. and i hope that within this list there are people skilled
> an experienced in programming.
>
> the example:
>
> .....
> 1 class Math:
> 2 {
> 3 public:
> 4 //Constructor contains definition of PI
> 5 Math (): PI (3,142) {}
> 6 ~Math () {}
> 7 float diameter (float radius)
> 8 {
> 9 return ( radius * PI )
> 10 }
> 11 private:
> 12 // declare PI. we cann´t assign a value
> 13 const float PI
> 14 }
>
> what does the ":" in line 4?? is it a kind of operator or what does it
> it seems strange to me and i didn´t find a solution in books.
> why you don´t write:
It calls the constructor for the constant. Obviously this isn't really
needed for a float, but it is generally good style to do this (it would
be required if it was a reference to an object with no default constructor).
IIRC according to the C++ standard this is the recomended way to initialise
a constant member in any case. Note that it would better code if the constant
was static anyway and better still if it used the constant defined in math.h.
Rich.
>
> Math::Math ()
> {
> pi=3,142;
> }
>
> greetings
> andreas schmitzer
>
--
Richard Moore rich at ipso-facto.freeserve.co.uk
http://www.robocast.com/ richard at robocast.com
http://developer.kde.org/ rich at kde.org
More information about the KDevelop
mailing list