• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

const

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
Codemadguy
Asked:
Codemadguy
1 Solution
 
WynCommented:
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
 
CodemadguyAuthor Commented:
Great pal,both the speed and answer!
It works.
Thanks.



0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now