Solved

syntax for initializing constants in a constructor

Posted on 2002-04-18
1
273 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

777 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