第一个简单例子
#include <string>
#include <iostream>
using namespace std;
class Test
{
public:
private:
int a;
int b;
//非const的static类型只能在类外定义,这里是声明
static int c;
//非const的static类型只能在类外定义,这里是声明
static int ret();
//Test类型是不完全类型,只能定义这个类型的引用或者指针,或者声明(不能定义)不完全类型作为参数或者返回类型的函数,顺便提一下,下面t1和t2是定义性声明,又叫定义又叫声明
Test &t1;//incomplete type 定义性声明t1
Test *t2;//incomplete type 定义性声明t2
Test com(Test t1,Test t2)const;
};
//非const的static成员在类外,因为static函数没有this指针,所以只能使用static成员,不能使用普通成员
int Test::c = 1234;
//非const的static成员在类外定义,因为static函数没有this指针,所以只能使用static成员,不能使用普通成员
int Test::ret(){return c;}
//成员函数在类外定义
Test Test::com