09 第九章 类属机制和命名空间.pptVIP

  • 3
  • 0
  • 约7.19千字
  • 约 32页
  • 2017-06-17 发布于湖北
  • 举报
#include iostream.h? template class TYPE void swap(TYPE x, TYPE y) // 声明一个函数模板swap { TYPE temp;? temp = x; x = y; y = temp; cout Calling generic version of swap().\n; }? void swap(int x, int y) // 重载swap,定义一特殊版本(不是模板) { int temp; ? temp = x; x = y; y = temp; cout Calling special version of swap().\n; }? int main() { int i = 10, j = 20;float x = 1.44, y = 3.14;char a = x, b = y; ? swap(i, j); // 调用swap()的特殊版本(非类属函数) (1) swap(x, y); // 调用类属函数实例化结果swap(float, float) (2) swap(a, b); // 调用类属函数实例化结果swap(char, char) (2) swap(i, b); // 调用swap()的特殊版本(编译时作隐式类型转换);VC6.0不支持 return 0; (3)

文档评论(0)

1亿VIP精品文档

相关文档