samedi 28 mars 2015

Behavior of a compiler for a const member variable in a class


When a const member variable is defined/declared in a function or globally, storage may or may not be assigned to the variable depending on the use of it. e.g. if we are using "extern" for providing the variable an external linkage, then compiler is bound to assign storage to the variable. Otherwise compiler will keep it in symbol table. Now when a const member variable is declared in a class like this:



class myClass {
const int myInt = 100;
}


In this situation, where does the compiler keep it?


Another question related to this which instantly came to my mind, should we declare it as private or protected?




Aucun commentaire:

Enregistrer un commentaire