C++静态(static)成员函数和成员变量的使用 |
您所在的位置:网站首页 › 调用成员变量的命令 › C++静态(static)成员函数和成员变量的使用 |
#include using namespace std;
class test { public: test() :a(0), b(0) { } ~test() { } void add() { a++; b++; c++; // 非静态函数可以使用静态成员变量 } static void adds() { //a++; b++; // 编译报错,静态成员函数无法使用非静态变量 c++; } static int getC() { cout
test a1, a2, a3; a1.print(); //0,0,10 a2.adds(); //0,0,12 a2.add(); //1,1,12 a3.print(); //0,0,12
//静态成员函数的调用方法 a3.getC(); //用对象. test::getC(); //类::
cout |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |