A constant integral

T

Tomás

When you have a constant integral in a program, like the population of a
town, how do you declare it? A const variable or an enum?

Up until now I've always used variables, e.g.:

unsigned const population_dublin = 8274816;


I'm flipping through pages of Bjarne's book though at the moment, and
enum's seem pretty handy, as in:

enum { population_dublin = 8274816 }


Which style would you advocate?

-Tomás
 
V

Victor Bazarov

Tomás said:
When you have a constant integral in a program, like the population of a
town, how do you declare it? A const variable or an enum?

Whatever floats your boat.
Up until now I've always used variables, e.g.:

unsigned const population_dublin = 8274816;

Is it really 'const'? I wonder, nobody is born and nobody dies in Dublin?
I'm flipping through pages of Bjarne's book though at the moment, and
enum's seem pretty handy, as in:

enum { population_dublin = 8274816 }


Which style would you advocate?

The former unless you need to place it in a class (as 'static') and your
compiler is too old to support integral static const initialisation in the
class definition.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top