目录

2018年12月23日

error: no matching function for call to ×××

  • 代表没有找到匹配函数的相关参数,可能的原因有:

    1. 参数类型不匹配;
    2. 参数构造错误,例如构造函数CLRead read_buff()就是一种错误的构造,导致read_buff无法被识别, 出现note: no known conversion for argument 1 from ‘CLRead (*)()’ to ‘CLRead*’
    3. 函数名称写错。

2018年12月10日

error: expected ‘)’ before ‘*’ token

  • 文件中的一些类没有被声明。导致的原因可能是:

    1. 自定义头文件与系统中的文件重叠,导致自定义文件没有被加载。但是 file.h是系统定义的头文件。这导致自己定义的file.h被覆盖。
    2. 加载了正确的自定义头文件,但是没有声明要使用的自定义类。
// 错误
#define FILE_H
#include "file.h"
#endif

// 正确
#define FILE_H
#include "myfile.h"
#endif

class CLFileBuff;  // 声明后才能使用,要不然也会出现这类错误

参考资料
error: expected ')' before '*' token

2018年11月15日

error: invalid conversion from ‘const char*’ to ‘char*’

  • 常量指针无法直接赋值给普通指针,如果不得不赋值,要通过强制类型转换
  • 但是如果赋值过程发生在函数变量处,不会报错,可能是因为自动进行了强制类型转换
// 错误
char* prt;
prt = str;

// 正确
char* prt;
prt = (char*)str;

2018年11月11日

error: a storage class can only be specified for objects and functions

  • 声明自定义类时,不能加static
// 错误
// file: C.h
class C{
};
// file: main
#include "C.h"
static class C;
... ...

// 正确
// file: C.h
class C{
};
// file: main
#include "C.h"
class C;
... ...

error: cannot call member function ××× without object

  • 调用类内的函数时,必须通过实例来调用,不可以直接通过类名调用
// 错误
class C{
    int func(){}
};

int c = C::func();
... ...

// 正确
class C{
    int func(){}
};

C temp;
int c = temp.func();
... ...

error: uninitialized reference member in ××× [-fpermissive]

  • 没有初始化引用
// 错误
class C{
    int a;
    int &r;
    C();
};
C::C(){
    a = 1;
}
... ...

// 正确
class C{
    int a;
    int &r;
    C();
};
C::C():r(a){
    a = 1;
}
... ...

error: passing ‘const ×××’ as ‘this’ argument discards qualifiers [-fpermissive]

  • 调用const变量时,相关函数没有明确是const的,可能存在被修改风险
// 错误
#include<iostream>
class C{
private:
    int a;
public:
    bool func(){
        cout << "hello: " << this->a << endl;
        }
    C(const C& c){
        c.func();
    }
};
C c1;
C c2(c1);

// 正确
#include<iostream>
class C{
private:
    int a;
public:
    bool func() const{
        cout << "hello: " << this->a << endl;
        }
    C(const C& c){
        c.func();
    }
};
C c1;
C c2(c1);

参考资料
error: passing 'const …' as 'this' argument of '…' discards qualifiers
error:passing 'const Student' as 'this' argument of 'void Student::print()' discards qualifiers

error: default argument given for parameter 2 of ×××

  • c++可以在类的声明中,也可以在函数定义中声明缺省参数,但不能既在类声明中又在函数定义中同时声明缺省参数。
// 错误
class C{
   C(int a=1);
}
C::C(int a=1){;}

// 正确
class C{
   C(int a=1);
}
C::C(int a){;}
};

2018年11月10日

error: new types may not be defined in a return type

  • 定义类时在最后“}”后面没有“;”
// 错误
class C{
    ... ...
}

// 正确
class C{
    ... ...
};

error: two or more data types in declaration of ...

  • 头文件相互包含,使用如下方法解决
#ifdef ××××    //定义一个宏,通常是该头文件名大写
#define ××××
#endif

error: ... does not name a type

  • 定义该类时,没有用class关键字,例如:
// 定义C类
// 错误
C{
    ... ...
};

// 正确
class C{
    ... ...
};

error: stray ‘\357’ in program

  • 一般是出现了中文符号

error: ××× does not name a type

  • 在包含相应有文件的情况下,仍然会出现没有定义的情况,这是因为没有在该文件下声明该类型,如下:
// 错误
// file: C.h
class C{
    ... ...
};
// file: test.h
#include "C.h"
C test;
... ...

// 正确
// file: C.h
class C{
    ... ...
};
// file: test.h
#include "C.h"
class test;

C test;
... ...

error: ‘virtual’ outside class declaration

  • 在类的外部定义虚函数时,不用再声明为"virtual"
// 错误
class C{
    virtual C();
};

virtual C(){
    ... ...
}

// 正确
class C{
    virtual C();
};

C(){
    ... ...
}

error: expected primary-expression before ‘const’

  • 因为在调用函数时,仍然带有变量类型,如下:
// 错误
const char* pathname = "hello.txt";
oflag = O_RDWR|O_APPEND;
this->_fd = open(const char* pathname, int oflag);

// 正确
const char* pathname = "hello.txt";
oflag = O_RDWR|O_APPEND;
int fd = open(pathname, oflag);

C++编译错误杂记的更多相关文章

  1. xamarin.forms新建项目android编译错误

    vs2015 update3 新建的xamarin.forms项目中的android项目编译错误.提示缺少android_m2repository_r22.zip,96659D653BDE0FAEDB ...

  2. 《转载》使用org.w3c.dom.Element的setTextContent()、getTextContent()方法时出现编译错误

    今天在更新项目后进行编译时,出现如下错误一堆: 编译错误 Google之,在stackoverflow上看到如下的解决方法: I came here with the same problem. Ev ...

  3. asp.net教程:编译错误同时存在于不同dll中

    asp.net 编译错误类型“同时存在于”不同的dll中. 出现这种错误大概有三种情况: 1.ASPX页面,一个*.ASPX,对应着一个*.cs文件,两者其实是一个文件,通过两者实现代码分离,每个*. ...

  4. VS2010出现FileTracker : error FTK1011编译错误的解决办法

    VS2010出现FileTracker : error FTK1011不知道是不是vs2010的一个bug,反正有人提交了. FileTracker : error FTK1011编译错误的解决办法有 ...

  5. PowerDesginer 生成的Oracle 11g 组合触发器代码编译错误(29): PLS-00103

    问题描述: 采用PowerDesigner15针对Oracle 11g 创建物理数据模型,想实现一个字段的自增,采用如下步骤: 1.创建序列,命名为Sequence_1; 2.在自增字段编辑窗口中,选 ...

  6. 我看见的第一个XCODE编译错误 - Command /applications.../clang failed with exit code 1

    开始用XCODE学习Apple相关开发的东东,写些demo熟悉Object C,一直还没看见什么问题,昨晚在家把一些demo上传到代码服务器,今天在另外一台机器上下载下来编译,出现了问题: Preco ...

  7. eclipse 编译android程序 编译错误

    windows->show view -> problems, 这个窗口的内容即为 编译错误的内容.

  8. 一个C++宏定义与枚举定义重复的编译错误

    C++的开发效率低是众所周知的,原因比如有: 语言复杂度高 编译效率低 工具链不够完整高效(尤其是linux下) 另外一个恐怕是不少编译错误让人摸不着头脑,今天碰到一个,举个例子: #include ...

  9. java编译错误 程序包javax.servlet不存在javax.servlet.*

    java编译错误 程序包javax.servlet不存在javax.servlet.* 编译:javac Servlet.java 出现 软件包 javax.servlet 不存在 软件包javax. ...

随机推荐

  1. Hadoop学习---Hadoop的HBase的学习

    Hbase Hbase的特点: Hbase是bigtable的开源的仿制版本 建立在HDFS之上 可靠性,靠性能 大:一个表可以有上亿行,上百万列 面向列:面向列(族)的存储和权限控制,列(族)独立检 ...

  2. spring初始化完成后执行初始化数据方法

    Spring提供的解决方案三种: 1.InitializingBean package com.foriseland.fsoa.fabricca; import com.foriseland.fsoa ...

  3. ROS Create a Catkin Workspace

    Step1 : First, create the top level catkin workspace directory and a sub-directory named src (pronou ...

  4. 在Go语言中记录log:seelog包

    前两周调bug调的吐血,虽然解决了但是还是挺浪费时间的.跟同事聊了聊,觉得我们现在项目中的日志记录太少了,导致出了问题不知道怎么下手,还得自己改代码记录日志,然后排查问题.这样如果将来还有bug的话还 ...

  5. BZOJ2194:快速傅立叶之二(FFT)

    Description 请计算C[k]=sigma(a[i]*b[i-k]) 其中 k < = i < n ,并且有 n < = 10 ^ 5. a,b中的元素均为小于等于100的非 ...

  6. 【[POI2006]OKR-Periods of Words】

    很妙的一道题 感觉又加深了对\(KMP\)还有\(next\)数组的理解 先来看看这个鬼畜的题意,大致就是给你一个字符串,对于这个字符串的每一个前缀,要去找到这个前缀的一个最长的前缀,使得前缀成为这个 ...

  7. 简单使用Spring Boot+JpaRepository+hibernate搭建项目

    sql: -- -------------------------------------------------------- -- 主机: 127.0.0.1 -- 服务器版本: 10.3.9-M ...

  8. 如果js设置移动端有两种方式 大家可以参考

    //使用em单位 var scaleObj = { documentEle : document.documentElement, deviceWidth : document.documentEle ...

  9. HDU 2082 找单词 (普通型 数量有限 母函数)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2082 找单词 Time Limit: 1000/1000 MS (Java/Others)    Me ...

  10. Matplotlib中中文不显示问题

    我们在使用jupter进行数据分析的时候,会接触到Matplotlib这个库,它是用来进行可视化数据分析的,在一个图中,我们常常会加入一些中文来进行说明.当我们加入中文的时候会出现下图所示的样子: 可 ...