C++ 类的static成员
来源:互联网 发布:网络钟点工陪人聊天 编辑:程序博客网 时间:2024/06/06 13:04
#include<iostream>
using namespace std;
class Tank
{
public:
Tank()
{
count++;
}
~Tank()
{
count--;
}
static int getCount();
private:
static int count;
};
int Tank::count=0;
int Tank::getCount() // 注意 外面定义不用加static
{
return count;
}
int _tmain(int argc, _TCHAR* argv[])
{
Tank t1;
Tank t2;
cout<<Tank::getCount()<<endl;
Tank t3;
cout<<Tank::getCount()<<endl;
system("pause");
return 0;
using namespace std;
class Tank
{
public:
Tank()
{
count++;
}
~Tank()
{
count--;
}
static int getCount();
private:
static int count;
};
int Tank::count=0;
int Tank::getCount() // 注意 外面定义不用加static
{
return count;
}
int _tmain(int argc, _TCHAR* argv[])
{
Tank t1;
Tank t2;
cout<<Tank::getCount()<<endl;
Tank t3;
cout<<Tank::getCount()<<endl;
system("pause");
return 0;
}
注意:1.静态数据成员必须单独初始化
2.静态成员函数不能使用非静态成员函数和非静态数据成员。
1 0
- c++-类的static成员
- c/c++ 类的static成员
- C/C++的static成员
- C++static成员的使用
- static c ,C++类static 成员变量
- static c ,C++类static 成员变量
- static C,C++类static 成员变量
- C++:类内static成员
- static类成员(C++)
- 类的static成员
- 类的static成员
- 类的static成员
- C++static类成员,static类成员函数
- 【C++】类的静态常量数据成员! static const
- c++static数据成员的使用。
- 【C/C++】类中的const成员 static成员
- 【C/C++】类中的static成员、static const成员和const成员
- 关于C++/JAVA类中的static成员和对象成员的说法正确的是:
- svn提交报org.apache.subversion.javahl.ClientException: Filesystem has no item
- 游戏服务器数据库踩过的坑
- ios开发多线程篇——创建线程
- 游戏服务器,每秒需要处理百来次数据库的读写操作,如何设计比较好?
- Selenium - Why there is no need of external firefox driver like IE and chrome in selenium2.0?
- C++ 类的static成员
- CSS有4种定义方式--类+ ID+ 标签+ 伪类
- 音视频开发需要的一些工具总结
- Linear Programming Learning Notes (3) Degeneracy
- windows svn命令行客户端
- Redis测试分析(pipeline模式)
- 棋牌游戏服务器架构: 详细设计(三) 数据库设计
- 第八周上机实践项目-项目三-指向学生类的指针
- iOS: ARC和非ARC下使用Block属性的问题