错误1错误C4430:缺少类型说明符 - 假定为int . 注意:C不支持default-int

#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” .

回答(2)

2 years ago

函数main应具有返回类型int

int main()

2 years ago

就像友情消息所说,它不是main()而是int main()或int main(void)或int main(int argc,char * argv [])

另见What is the proper declaration of main?