Statements for constants
#define VALUE 100
const int value = 100;
const int * p_int;
int const * p_int;
int * const p_int;
void func(const int *);
void func(const int &);
const member variables behavior similar with normal const variables
const member functions promise not to modify member variables.
class Student
{
private:
const int BMI = 24;
// ...
public:
Student()
{
BMI = 25; //can it be modified? no
// ...
}
int getBorn() const
{
born++; //Can it be modified?
return born;
}
};
static members
static members are not bound to class instances
静态成员是不绑定到某一个实例的
class Student
{
private:
static size_t student_total; // declaration only
public:
Student()
{
student_total++;
}
~Student()
{
student_total--;
}
static size_t getTotal() {return student_total;}
};
// definition it here
size_t Student::student_total = 0;