第五周程序阅读(6)
来源:互联网 发布:windows 8的记事本 编辑:程序博客网 时间:2024/05/24 16:16
#include <iostream>using namespace std;class Test{private: static int val; int a;public: static int func(); static void sfunc(Test &r);};int Test::val=20;int Test::func(){ val+=val; return val;}void Test::sfunc (Test &r){ r.a=25; cout<<"Result3="<<r.a<<endl;}int main(){ cout <<"Resultl="<<Test::func()<<endl; Test a; cout<<"Result2="<<a.func()<<endl; Test::sfunc (a); return 0;}
运行结果:
学习心得:第一个是调用func函数,也就是20+20=40,第二次调用的时候,因为val是个静态数据成员,它的值是对象共享的,val的值已经变成了20,,因此输出的结果为40。接下来调用的是sfunc函数,因为也是个静态成员函数,在函数就有定义输出,所以是25。
0 0
- 第五周程序阅读(6)
- 第五周 阅读程序(6)
- 第五周 阅读程序(6)
- 第五周程序阅读(6)
- 第五周阅读程序6
- 第五周程序阅读
- 第五周阅读程序
- 第五周 程序阅读
- 第五周项目零:阅读程序(6):static .
- 第五周阅读程序6:静态变量
- 第五周程序阅读(2)
- 第五周程序阅读(3)
- 第五周程序阅读(4)
- 第五周 阅读程序(1)
- 第五周 阅读程序(2)
- 第五周 阅读程序(3)
- 第五周 阅读程序(4)
- 第五周 阅读程序(5)
- AT&T汇编学习笔记之数据类型
- AT&T汇编学习笔记之字符串
- HtmlUnit测试入门
- 提高MySQL数据库性能
- AT&T学习笔记汇编之调用汇编库
- 第五周程序阅读(6)
- 黑马程序员——Collections、Arrays、增强for、可变参数、静态导入
- AT&T学习笔记汇编之call
- Ihtmldocument2接口的使用
- 什么是ORB
- jQuery Mobile学习笔记(十)——扩展框架
- uvalive 3644(并查集)
- uboot移植过程中的运行地址和装载地址的区别
- 正则表达式语法