2
"The 'constancy' of a const object is imposed from the moment the constructor completes the initialization of the object until the destructor of that object is called" - Deitel,++
If the compiler "considers" a member to be present after the initialization of the object by the constructor, why does an attribution initialization generate errors ? Why only one boot per member initializer is accepted ?
Examples:
class Example
{
public:
const int num1;
int num2;
Example(int a, int b)
{
num1 = a; // Gera um erro
num2 = b;
}
}
class Example
{
public:
const int num1;
int num2;
Example(int a, int b)
: num1(a) // Funciona normalmente
{
num2 = b;
}
}