2013-11-27 76 views
0
#include<iostream> 

using namespace std; 

template <class T> 
void myswap(T & tmp1, T & tmp2) 
{  
    T temp; 
    temp = tmp1; 
    tmp1 = tmp2; 
    tmp2 = temp; 
    return; 
} 

main() 
{ 
    int x = 1; 
    int y = 20; 
    double p = 10.9, q = 23.36; 
    char s = 'o', t = 'u'; 

    myswap(x, y); 
    cout << "x=" << x << "and y=" << y << endl; 

    myswap(p, q); 
    cout << "p=" << p<< "and q=" << q << endl; 

    myswap(s, t); 
    cout << "s=" << s << "and t=" << t << endl; 

    return 0; 
} 

我使用visual studio 2013.當我運行此代碼時,編譯器給我提示消息「錯誤:缺少類型說明符-int假定C++不支持默認int」。錯誤1錯誤C4430:缺少類型說明符 - 假定爲int。注意:C++不支持default-int

+0

**請**避免使用標籤。他們對一切都造成嚴重破壞。 – chris

回答

3

功能主要應返回類型爲int是

int main() 
相關問題