Solved

syntax for initializing constants in a constructor

Posted on 2002-04-18
1
274 Views
Last Modified: 2006-11-17
I was having trouble initialing constant data
members of a class.
class class1{
const int standby;
const int shutdown;
};

class1::class1(){
standby = 0;
shutdown = 1;
}
It doesn't allow this, which makes sense since they are constants.
but since I cant do:
class class1{
const int standby = 0;
const int shutdown = 1;
};
What syntax is needed?

I'm not using #defines because I'm integrating
my code with other code which may use these names already.



0
Comment
Question by:mitchguy
1 Comment
 
LVL 86

Accepted Solution

by:
jkr earned 50 total points
ID: 6951401
Use

class1::class1() : standby ( 0), shutdown ( 1) {};
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question