Re: Syntax of constructor

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



That's called the initializer list.  I suggest you get a book that
explains these things.  C++ Primer or The C++ Programming Language
would be good.

Here is a link that explains this particular topic:
http://www.blueturnip.com/projects/edu/cs/cpp/initializer-lists.html

-Uday

On 3/20/06, Shriramana Sharma <samjnaa@xxxxxxxxx> wrote:
> A header file contains the following class declaration:
>
> class CAA2DCoordinate
> {
> public:
> //Constructors / Destructors
>         CAA2DCoordinate(): X(0), Y(0) {};
>
> //member variables
>   double X;
>   double Y;
> };
>
> Now what I do not understand is the line:
>
>         CAA2DCoordinate(): X(0), Y(0) {};
>
> I would have thought it would be:
>
> CAA2DCoordinate() { X = 0; Y = 0; }
>
> just like the QDate constructor:
>
>     QDate() { jd = 0; }
>
> What is the meaning of the colon ":" here, and what are the (0) things, and
> why are X and Y *outside* the braces?
>
> Thanks for your patience.
>
> --
>
> Tux #395953 resides at http://samvit.org
> playing with KDE 3.51 on SUSE Linux 10.0
> $ date [] CCE +2006-03-20 W12-1 UTC+0530
> -
> : send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
-
: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Assembler]     [Git]     [Kernel List]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [C Programming]     [Yosemite Campsites]     [Yosemite News]     [GCC Help]

  Powered by Linux