next up previous
Next: How do I call Up: class and struct Previous: How do I initialize

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
};



Alexis Angelidis (PhD) 2005-01-11