Plus.W 2015-03-19 14:42 采纳率: 20%
浏览 1636

求大神指点C++ template使用问题

图片说明
这是程序代码
图片说明
这是编译结果

我想试试用template写一个返回较小值的方法,但是为什么会出错呢?
还想请教的问题是如果用Mac的话,在terminal中编译和用Xcode编译有区别吗?谢谢

  • 写回答

3条回答 默认 最新

  • threenewbee 2015-03-19 15:02
    关注
     #include <iostream>
    using namespace std;
    
    template <typename T>
    T min(T &a, T &b)
    {
        return a > b ? b : a;
    }
    
    int main()
    {
        int i = 1, j = 2;
        int result = min(i, j);
        cout << result;
    }
    

    http://ideone.com/E9cqbV

    评论

报告相同问题?