正在加载图片...
面向对象程序设计 例2:/ example5 # include< iostream. h>∥预处理 class test{∥定义类test public:/定义类的公共部分 test(int y)xy;) 堂提要 void print((cout <<x << endl; private ∥定义类的私有部分 第五章C++基础 int x, 51C++概述 52数据和表达式 void maind()∥主函数 53基本语句 54函数 test ob(5);∥定义具体的对象 55数组与指针 ob. print(),/消息激活服务 print 结果 显示x的值5第五章 C++基础 5.1 C++概述 5.2 数据和表达式 5.3 基本语句 5.4 函数 5.5 数组与指针 例2: //example 5.2 #include <iostream.h> //预处理 class test { //定义类 test public: //定义类的公共部分 test(int y) {x=y;} void print( ) {cout << x << endl;} private: //定义类的私有部分 int x; }; void main( ) //主函数 { test ob(5); //定义具体的对象 ob.print( ); //消息激活服务 print } 结果 显示 x 的值5
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有