Solved

const

Posted on 2000-03-21
2
256 Views
Last Modified: 2010-05-18
I have trouble to initialize a const in class,where should I initialize it ?
A sample is ideal.

It's very urgent,please hurry up.

Thanks.
0
Comment
Question by:Codemadguy
[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
2 Comments
 
LVL 5

Accepted Solution

by:
Wyn earned 280 total points
ID: 2643342
You'd initialize those const variables in the constructor initializer list because const in class has different meaning versus in local or file scope.

class blah
{

const char blahwords;
public:
blah(char c='C');
}

blah::blah(char c):blahwords(c)
{
//other initializations.
}

Sincerely hope above helpful...

Regards
W.Yinan
0
 

Author Comment

by:Codemadguy
ID: 2643351
Great pal,both the speed and answer!
It works.
Thanks.



0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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. …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 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.

624 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