- 0
- 0
- 约6.49千字
- 约 26页
- 2021-11-30 发布于安徽
- 举报
* A Simple Circle Class To demonstrate creating objects, accessing data, and using functions TestCircle Run Pointers to Members A class member pointer can be declared using the operator ::* with the class name. For example: * class A { private: int m; public: void show(); }; int A::* ip = A::m; § 5.2 Defining Member Functions * return-type class-name :: function-name (parameters) { Function body } Identity label Scope resolution operation * Inline Declaration A member function can be implemented inside a class declaration automatically an inline function class A { public: A() { // do something; } double f1() { // return a number } double f2(); }; Inline function Inline function Regular function double A::f2() { // return a number } inline double A::f2() Inline function * Separating Declaration from Implementation Similar to the definition of function Declaration(声明): In classname.h file, conventionally Simply lists all the data fields, constructor prototypes, and the function prototypes. Implementation(实现): In classname .cpp file, conventionally Implements the constructors and functions. Circle.h Run Circle.cpp #include iostream using namespace std; class set{ int m, n; public: void display(void); int largest(void); }; int set::largest(void){ if(m=n) return m; else return n; } void set::display(){ coutlargest()\n; } Nesting of Member Functions * A member function can be called by another member function of the same class Via function name directly (no object name) Private Member Functions Normally: data in private; functions in public Some functions in private sections Can only be called by member function of its class To protect data from modifications by outsiders * class sample { int m; void read(void); public: void update(void); void write(void); }; § 5.3 Memory Allocation and Static Members * Memory of member functions -- Common for al
您可能关注的文档
- 高等数学课件:9-5 二阶线性常系数微分方程.ppt
- 高等数学课件:9-7常系数线性微分方程组.ppt
- 高等数学课件:10.1向量及其运算(1-30).ppt
- 高等数学课件:10.2 空间直角坐标系与向量代数(1-24).ppt
- 高等数学课件:10.3 平面与直线.ppt
- 高等数学课件:10.4.1曲面及其方程.ppt
- 高等数学课件:10.4.2二次曲面.ppt
- 高等数学课件:10.5向量函数 空间曲线.ppt
- 高等数学课件:10-1 收敛原理与数项级数.ppt
- 高等数学课件:10-2 正项级数.ppt
- 软件设计(II)教学课件:Chapter6 Constructors and Destructors.ppt
- 软件设计(II)教学课件:Chapter7 Operator Overloading and Type Conversions.ppt
- 软件设计(II)教学课件:Chapter8 Inheritance.ppt
- 软件设计(II)教学课件:Chapter9 Pointers, Virtual Functions and Polymorphism.ppt
- 软件设计(II)教学课件:Chapter10 Console IO Operations.ppt
- 软件设计(II)教学课件:Chapter11 Working with Files.ppt
- 软件设计(II)教学课件:Chapter12 Templates(模板).ppt
- 软件设计(II)教学课件:Chapter13 Exception Handling.ppt
- 软件设计(II)教学课件:Chapter15 String.ppt
- 软件设计(II)教学课件:Chapter17 Object-Oriented Systems Development.ppt
最近下载
- 2025年浙江省高考数学试卷(含答案及解析).docx
- CNAS-CL01-2025实验室风险和机遇识别分析评估及控制措施表【实验室风险.docx
- 小学五年级数学小数混合运算计算专项练习题(每日一练,共5份).pdf VIP
- 水生生物学养殖水域生态学生产力.ppt VIP
- 小学五年级数学小数混合运算计算专项练习题(每日一练,共18份).pdf VIP
- 2024中考英语必背中考词形变化总汇.pdf VIP
- 防水混凝土施工工艺标准.pdf VIP
- 云南省中考英语答题卡2.docx
- 小学五年级数学小数混合运算计算专项练习题(每日一练,共6份).pdf VIP
- 水生生物学——养殖水域生态学 第 十章 初级生产力.ppt VIP
原创力文档

文档评论(0)