{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Educn sqrt2 sqrtintint sqrtdouble sqrt20

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: def_val> class Cont{/*…*/}; 整数模板参数常常用于提供大小或者界限, 必须为常量 Beijing University of Posts & Telecommunications Beijing [email protected] 模板参数示例 template<class T, int i> class Buffer { T v[i]; int sz; public: Buffer():sz[i]{} }; Buffer<char,127> cbuf; Buffer<Record,9> rbuf; 模板参数可以使常量表 达式,具有外部连接的 对象或者函数的地址, 或者非重载的指向成员 的指针,用作模板参数 的指针必须具有&of的形 式,其中of是对象或者 函数的名字;或者具有f 的形式,f必须是一个函 数名,到成员的指针必 // 当运行效率和紧凑性特别重要时,可以使 须具有&X::of的形式, 用Buffer这类容器,将数组大小作为参数传 这里的of是一个成员名 递,可以使Buffer的实现避免使用自由存储 (例如vector或者string) Beijing University of Posts & Telecommunications Beijing [email protected] 13.2.4 类型等价 给出一个模板,可以为它提供模板参数,以 生成一些类型 String<char> s1; String<unsigned char> s2; Sring<int> s3; 对于同一模板使用同一组模板 参数,将总是表示同一个生成 出的类型 typedef unsigned char Uchar; String<Uchar> s4; String<char> s5; typedef并不引入新的类型, 所以String<Uchar>和 String<unsigned char>是同 样的类型(同一组模板参数) Buffer<String<cha...
View Full Document

  • Fall '13
  • XiaoshengTang
  • Return statement, Tsinghua University, Void type, Beijing, Peking University, BeiJing University of Posts

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern