类中声明次序:public、protected、private,如果某一块没有,直接忽略。
每一块中,声明次序如下:
(1)常量;
(2)构造函数;
(3)析构函数;
(5)成员函数,含静态成员函数;
(6)数据成员,含静态数据成员;
class MyClass {
public:
static const int CONSTANT; // 常量
MyClass(); // 构造函数
~MyClass(); // 析构函数
void function(); // 成员函数
static void staticFunction(); // 静态成员函数
private:
static int staticData; // 静态数据成员
int data; // 数据成员
};
const int MyClass::CONSTANT = 0; // 常量定义