初始化列表

class Person
{
 public:
  Person() :a(10),b(20),c(30)
  {
    cout<<"初始化列表的调用"<<endl;
  }
  int a;
  int b;
  int c;
};

静态成员函数

  • 程序共享一个函数
  • 静态成员函数只能访问静态成员变量
#include <iostream>
using namespace std;
class Compute
{
public:
	static int Dg(int n)
	{
		if (n == 1)
			return 1;
		else
			return n+Dg(n-1);
	}
};

int main()
{
	int ret = Compute::Dg (100);
	cout << ret << endl;
	system("pause");
	return 0;
}

静态成员的两种访问方式:通过对象访问,通过类名访问

this指针

class Person
{
public:
	Person(int age)
	{
		this->age = age;
	}
	int age;
};