Re: question about constants in C++
From: Method Man (a_at_b.c)
Date: 11/25/04
- Next message: Karl Heinz Buchegger: "Re: virtual constructor"
- Previous message: Siemel Naran: "Re: Do all pointers have same size?"
- In reply to: Jonathan Mcdougall: "Re: question about constants in C++"
- Next in thread: Matthias Käppler: "Re: question about constants in C++"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 25 Nov 2004 03:40:50 -0500
"Jonathan Mcdougall" <jonathanmcdougall@DELyahoo.ca> wrote in message
news:uFbpd.70754$3u6.2295196@wagner.videotron.net...
> john smith wrote:
> > I have a question about the best way to use constants in C++. There
seem to
> > be variations in the way that they are used, and I am confused as to
what I
> > should be using. Basically since the constant is used in only one
class,
> > should I try to scope it to just that class? to the file?
> > what are the thoughts out there.
>
> If a constant is part of the class :
>
> 1. if the constant will be the same for all objects of that class (PI
> for a class Math for example), make it a static constant member.
>
> // my_math.h
> class Math
> {
> private:
> const float PI;
> };
>
[snip]
I assume you meant "static const float PI;"?
- Next message: Karl Heinz Buchegger: "Re: virtual constructor"
- Previous message: Siemel Naran: "Re: Do all pointers have same size?"
- In reply to: Jonathan Mcdougall: "Re: question about constants in C++"
- Next in thread: Matthias Käppler: "Re: question about constants in C++"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]