类定义(2) 三种inline 声明方式
2014-08-30 09:23
253 查看
using namespace std; class Screen { public: typedefstring::size_type index; Screen(index ht,index wd,const string& conts);//非内联函数 Screen(int ht=0,index wd=0) //1.内联 :contents(ht*wd,'A'),cursor(0),height(ht),width(wd) {} char Get() const; //2.内联 inline char Get(index r,index c) const; //3.内联 private: string contents; string::size_type cursor; string::size_type height,width; }; Screen::Screen(index ht,index wd,const string &conts) :contents(conts),cursor(0),height(ht),width(ht) {} inline char Screen::Get() const //2.显式内联函数 { return contents[cursor]; } char Screen::Get(index r,index c) const //3.内联函数 { index row=r*width; return contents[row+c]; } int main() { Screen a(10,16,string("hello")); cout<<a.Get()<<endl; getchar(); return 0; }
相关文章推荐
- js中函数的三种定义方式、函数声明、函数同名重复、函数删除、
- jbpm解析流程定义的三种方式
- HTML中定义CSS样式的三种方式
- 基于JavaScript 声明全局变量的三种方式详解
- Objective-C的.h与.m文件中公有和私有函数的声明和定义方式[学习笔记]
- JavaScript 定义function的三种方式小结
- perl中三种定义变量方式的一点区别
- 探讨JavaScript中声明全局变量三种方式的异同
- JavaScript声明全局变量三种方式的异同
- jbpm解析流程定义的三种方式
- JS之函数定义的三种方式
- C++中定义类的三种方式
- JavaScript声明全局变量三种方式的异同
- 页面中声明方式定义的用户控件与页面事件的执行顺序
- JavaScript声明全局变量的三种方式
- jbpm解析流程定义的三种方式
- PHP中来定义字符串的三种方式(第三章 字符串与正则表达式)
- PHP字符串三种定义方式
- 有效的XML: DTD(文档类型定义)介绍与三种使用方式
- C常见问题之结构的声明和结构变量的定义方式