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
};
0 comments:
Post a Comment