Solved

syntax for initializing constants in a constructor

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 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.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now