c++ - 错误1 error C4430 : missing type specifier - int assumed. 注意:C++不支持default-int

标签 c++ compiler-errors

#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/

相关文章:

c++ - CLion 导入具有依赖项的现有 cmake 项目

c++ - 为什么这段c++找不到结构成员 'filename'?

c++ - 列出所有函数仍在尝试检索我从二叉搜索树中删除的节点

c++ - 如何设置从 CreateProcess 创建的进程的搜索路径

c++ - 数组下标c++的无效类型 ‘int[unsigned int]’

c++ - 为什么我在从 time(NULL) 播种随机数生成器时收到可能丢失数据的警告?

c++ - 在运行时检查我是否可以实例化(抽象)类

c++ - boost Range 库会成为下一个 C++ 标准的一部分吗?

c++ - &token 之前预期的构造函数、析构函数或类型转换

ruby - RedHat C 编译器不编译?