Subscribe For Free Updates!

We'll not spam mate! We promise.

Apr 14, 2013

How do I initialize a const member?



How do I initialize a const member?

Since the value of a const member cannot be assigned with operator =, its value must
be initialized as follows:
struct A
{
const int id;
A(int i): id(i) {} // attribute id is initialized to the value of parameter i
};

TechniqZone Socializer Widget
SOCIALIZE IT →
FOLLOW US →
SHARE IT →

0 comments:

Post a Comment