#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”。
最佳答案
main函数的返回类型应该是int
int main()
关于c++ - 错误1 error C4430 : missing type specifier - int assumed. 注意:C++不支持default-int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20250792/