编程错误集锦【更新中......】

1.中文空格导致编译出错

报错如下:

 typedef int Data_type;  //定义数据类型
 ^
../include/link.h:8:1: error: stray ‘\200’ in program
../include/link.h:8:1: error: stray ‘\200’ in program
../include/link.h:8:1: error: stray ‘\343’ in program
../include/link.h:8:1: error: stray ‘\200’ in program
../include/link.h:8:1: error: stray ‘\200’ in program
../include/link.h:11:2: error: stray ‘\343’ in program
  Data_type data;  //
  ^
../include/link.h:11:2: error: stray ‘\200’ in program
../include/link.h:11:2: error: stray ‘\200’ in program
../include/link.h:11:2: error: stray ‘\343’ in program
../include/link.h:11:2: error: stray ‘\200’ in program
../include/link.h:11:2: error: stray ‘\200’ in program
make[1]: *** [link.o] Error 1

这个错对新手来说,实在太不友好、太无情了
完全摸不着头脑
代码看了10遍
都没找出错误
原来竟是出现了中文的空格
根本看不出来
注释前,分号后容易出现!!!!

2.E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

这个问题通常发生在软件包管理器(例如 apt-get)无法从配置的存储库中下载或检索必要的软件包时。

可在终端中运行以下命令:

sudo apt-get update && sudo apt-get upgrade

此命令会更新软件包列表并升级系统中任何过时的软件包。

如果错误仍然存在,使用 --fix-missing 标志运行该命令,

sudo apt-get update --fix-missing

此标志指示软件包管理器尝试修复任何缺失的软件包或依赖项。

如果这些解决方案都不起作用,
检查网络连接或验证配置的存储库是否正确。

3. 调用私有空间构造函数

error: ‘Student::Student(std::string, int, std::string)’ is private
  Student(string _name, int _age, string _sex){
  ^

这个错误提示表明你正在尝试调用一个私有的构造函数。

私有构造函数意味着它只能在类的内部使用,无法从外部访问或调用。

解决:

  1. 将构造函数的访问修饰符改为public,以便从类的外部进行访问和调用。

  2. 添加一个公有的静态工厂方法:如果你想保持构造函数的私有性,并且仍然需要从外部创建类的对象,你可以添加一个公有的静态工厂方法,该方法内部调用私有的构造函数并返回一个新的对象。示例:

public:
    static Student createStudent(string _name, int _age, string _sex) {
        return Student(_name, _age, _sex);
    }

private:
    Student(string _name, int _age, string _sex) {
        // constructor implementation
    }

通过调用Student::createStudent()来创建对象。

  1. 在类的其他成员函数中创建对象:如果你只需要在类的内部使用该构造函数创建对象,可以在其他成员函数中调用该构造函数来创建对象。

4. 调用成员函数忘加括号

error: statement cannot resolve address of overloaded function
  stu1.study;
  语句无法解析重载函数的地址

这个错误提示说明你正在尝试使用函数调用语法来访问一个成员变量,

但是该成员变量是一个函数重载的情况,导致编译器无法确定具体要访问哪个函数。

5.编译没加库-lpthread

In function `handle_client':
server.c:(.text+0x4b9): undefined reference to `do_insert'
server.c:(.text+0x5ab): undefined reference to `insert_ufiles'
server.c:(.text+0x5ff): undefined reference to `insert_pubfiles'
server.c:(.text+0x6ae): undefined reference to `insert_ufiles'
server.c:(.text+0x6ed): undefined reference to `insert_pubfiles'
collect2: error: ld returned 1 exit status
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值