zoukankan      html  css  js  c++  java
  • C++模板学习

     1 // templateTest.cpp : 定义控制台应用程序的入口点。
     2 //
     3 
     4 #include "stdafx.h"
     5 #include <iostream>
     6 
     7 using namespace std;
     8 /*模板参数只能使用一种数据类型,如果要在函数中使用多种数据类型,可以定义多个typename,
     9 例如:接受两种参数的模板定义:template<typename T,typename Y>*/
    10 
    11 template<typename T,typename Y>
    12 void Swap(T &num1, Y &num2);
    13 
    14 void show(int &, double &);
    15 
    16 int main()
    17 {
    18     int x = 100;
    19     double y = 23.98;
    20     show(x, y);
    21     Swap(x, y);
    22     show(x, y);
    23     system("PAUSE");
    24     return 0;
    25 }
    26 
    27 
    28 template<typename T,typename Y>
    29 void Swap(T &num1, Y &num2)
    30 { 
    31     T temp;
    32     temp = num1;
    33     num1 = num2;
    34     num2 = temp;
    35 }
    36 
    37 void show(int &number1, double &number2)
    38 {
    39     cout << "数字1为:" << number1 << endl;
    40     cout << "数字2为:" << number2 << endl;
    41 }

    a win32 console application!!

  • 相关阅读:
    mybatis-config.xml详解
    过滤器与拦截器
    Tomcat 部署web 项目
    Tomcat架构
    git stash
    AbstractQueuedSynchronizer 源码解读(转载)
    Kafka 转载
    Oracle数据库TNS详解
    Oracle建表知识全面详解
    Oracle高级教程
  • 原文地址:https://www.cnblogs.com/Leekin/p/4713943.html
Copyright © 2011-2022 走看看