?
Solved

const members

Posted on 2004-10-30
2
Medium Priority
?
288 Views
Last Modified: 2010-04-01
Could someone please explain to me how to create constant members. i tried initializing the constant in the constructor, but the compiler complains and requests that i initialize the member in the constructor base/member initializer list, what does this mean??

0
Comment
Question by:cpu4ghz
2 Comments
 
LVL 8

Accepted Solution

by:
mnashadka earned 200 total points
ID: 12453034
The member initialization list is the section in the constructor right after the colon (:).  It would look something like:

// A.h
class A
{
public:
  A();
private:
  const x;
};

// A.cpp
A::A()
: x(321) // Initialize in the member initialization list
{
}

Hope this helps.
0
 

Author Comment

by:cpu4ghz
ID: 12453071
Thanks alot for your help.
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.

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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

599 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