c++对象
来源:互联网 发布:武工队后勤部淘宝店铺 编辑:程序博客网 时间:2024/06/05 16:54
C++程序设计(c++对象)
What is an object?
Object is variable in programming languageObjects=Attributes+ServicesObject consists of Data and Operations 1.Date:the properties or status2.Operations:the functions
示例1
创建一个c++类:
class pointer{ public: pointer();//定义构造方法,方法默认在创建对象时执行 void show();//定义一个公有方法 private://定义私有成员 int a; int b; int c;};
创建一个pointer对象
pointer test=new pointer();
面对对象的理念
Objects send and receive messages (objects do things!)
• Messages are–Composed by the sender–Interpreted by the receiver–Implemented by methods• Messages • May cause receiver to change state • May return results
class-defines>object object-is>class
• Objects (cat) • Represent things, events, or concepts • Respond to messages at run-time• Classes (cat class) • Define properties of instances • Act like types in C++
oop Characteristics
1.Everything is an object. 2.A program is a bunch of objects telling each what to do by sending messages. 3.Each object has its own memory made up ofother objects. 4.Every object has a type. 5.All objects of a particular type can receivethe same messages
The Hidden Implementation
- Inner part of an object, data members to present
its state, and the actions it takes when messages
is rcvd is hidden - Class creators vs. Client programmers
–Keep client programmers’ hands off portions they should not touch.
–Allow the class creators to change the internal working
of the class without worrying about how it will affect the client programmers
示例2
利用面对对象显示初始化时间
#include<iostream>using namespace std; class Numbershow{ private: int limit; int value; public: Numbershow(int limit,int value){ this->limit=limit; this->value=value; } int printnum(){ return value; }};class Clockshow{ private: Numbershow min; Numbershow hour; public: //在构造函数中采用参数初始化表 Clockshow(int m,int h):min(60,m),hour(12,h){ cout<<"初始化时间"<<hour.printnum()<<":"<<min.printnum()<<endl; }};int main(){ Clockshow clock(8,9); return 0;}
结果
初始化时间9:8
0 0
- 【c++】对象
- C面向对象-构建对象
- C/C++:C++面向对象
- C与面向对象
- c++---类和对象
- C 面向对象程序设计
- c实现面向对象
- Obj-c面向对象
- objective-c对象初始化
- JAVA面向对象C
- OBJECT-C 对象初始化
- 【C++】对象和指针
- c面向对象设计
- c++-->面向对象
- 面向对象(C++)
- c对象创建
- c实现"对象"
- [C#] 面向对象
- Hibernate基于主键的多对多映射2015-11-11
- 线性表
- 蓝懿iOS 技术内容交流和学习心得 11.11
- PostgreSQL安全指南 - Postgres2015全国用户大会--重磅嘉宾佳作分享(周正中)
- OnLongClickListener接口接入
- c++对象
- 修改FoxitReader (福昕PDF阅读器)最近打开文档数目的上限
- 全面解析Linux 内核 3.10.x - 开始编译<一>
- 0102 混蛋罗心得[敌人方位(多图, 慎入)]
- [Django架构流程分析]了解Django Middleware的几个关键方法
- yii2 安装
- 寄居蟹与海葵
- Struts例子——第一篇
- win7 64位 卸载ie11 方法