标题:函数模板问题
取消只看楼主
小亦庄葛三娘
Rank: 1
等 级:新手上路
帖 子:24
专家分:5
注 册:2016-10-23
结帖率:25%
已结贴  问题点数:10 回复次数:0 
函数模板问题
程序代码:
template <typename  T>
void swap(T &a, T &b);

int main()
{
    int i = 10;
    int j = 20;
    cout << "i, j = " << i << ", " << j << ".\n";
    cout << "using complier generated int swapper:\n";
    swap(i, j);
    cout << "now i, j = " << i << ", " << j << ".\n";
    
    double x = 24.5;
    double y = 81.7;
    cout << "x, y = " << x << ", " << y << ".\n";
    cout << "using complier generated int swapper:\n";
    swap( x, y);
    cout << "now x, y = " << x << ", " << y << ".\n";
    
    return 0;
}

template <typename T>
void swap(T &a, T &b)
{
    T temp;
    temp = a;
    a = b;
    b = temp;
}





在学c++ primer plus里面的例题,但是编译不出来,求大神指教

[此贴子已经被作者于2017-3-21 14:10编辑过]

搜索更多相关主题的帖子: color 
2017-03-21 14:08



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-475323-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.078097 second(s), 9 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved