?
Solved

syntax for initializing constants in a constructor

Posted on 2002-04-18
1
Medium Priority
?
277 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 6951401
Use

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

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

765 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