c++static关键字
来源:互联网 发布:数据科学入门 编辑:程序博客网 时间:2024/06/03 09:25
#include <iostream>
using namespace std;
class A{
static int i;
public:
static int j;
static void set_i(int a){ //用静态方法访问静态属性
i = a;
}
void print()
{
cout << "i=" << i << "\t" << "j=" << j << endl;
}
A(){
cout << "A()" << endl;
}
~A(){
cout << "~A()" << endl;
}
};
int A::j = 100; //被static修饰的属性必须进行全局初始化
int A::i = 50;
void fun(){
A a;
}
int main()
{
fun();
A a;
A b;
a.set_i(12);
b.set_i(22);
b.j = 200; //被static修饰的属性是所有对象共有的
a.print();
b.print();
cout <<A::j<< endl; //对于static修饰的属性的引用
return 0;
}
using namespace std;
class A{
static int i;
public:
static int j;
static void set_i(int a){ //用静态方法访问静态属性
i = a;
}
void print()
{
cout << "i=" << i << "\t" << "j=" << j << endl;
}
A(){
cout << "A()" << endl;
}
~A(){
cout << "~A()" << endl;
}
};
int A::j = 100; //被static修饰的属性必须进行全局初始化
int A::i = 50;
void fun(){
A a;
}
int main()
{
fun();
A a;
A b;
a.set_i(12);
b.set_i(22);
b.j = 200; //被static修饰的属性是所有对象共有的
a.print();
b.print();
cout <<A::j<< endl; //对于static修饰的属性的引用
return 0;
}
阅读全文
0 0
- c/c++-----static关键字
- 【C/C++】关键字static
- c/c++static关键字
- C++-static 关键字
- c/c++ static关键字
- C 关键字extern、static
- c语言关键字static
- C/C++ static 关键字
- c static关键字理解
- c++static关键字
- C关键字--static
- c语言static关键字
- C语言关键字static
- C语言static关键字
- c中static关键字
- 关键字static(c语言)
- C语言-关键字static
- C static 关键字
- Android数据库框架-----GreenDao3的相关使用和版本升级更新
- Java Type类型详解
- pt-kill 杀死mysql 死锁
- C++——NOIP2016提高组day2 t2——蚯蚓
- Kotlin Reference (二) Idioms
- c++static关键字
- 高级装配 —— 如何处理自动装配的歧义性?
- 键盘事件和鼠标事件
- [zicreate]Altium Designer 15原理图与PCB设计视频课程
- hdu6055 17多校二1011 Regular polygon
- npm install 报NO REPOSITORY FIELDS No README data
- CodeForces830B【树状数组+线段树】
- 1149: 组合三位数之二
- 图的深度优先遍历(DFS)和广度优先遍历(BFS)