C++错误集合


3.cpp:30:1: error: no declaration matches 'Student::Student(std::__cxx11::string)'Student::Student(string name) ^~~~~~~

构造函数定义的时候,编译器没有选出适合的构造函数声明

[Error] ld returned 1 exit status

这种情况一般会出现在代码错误的
析构函数没有定义
那么回去看了看代码,发现是 静态变量是要初始化才能用的。

[Error] stray '\241' in program

stray '\241' in program :该错误是指源程序中有非法字符,需要去掉非法字符一般说来,如果你从其他地方复制代码过来,可能会出现这个问题。中文空格中文引号中文各种标点符号都会引起这个问题解决办法是复制过来的 code 重新输入一遍即可, 切不可偷懒!

[Error]in C++98 ‘arr‘ must be initialized by constructor, not by‘{...}‘

在decc++, 点击工具, 加入以下命令, 然后打上勾勾, 点击确定即可。
-std=c++11

聚合类十分之苛刻;
[Error] could not convert '{"97805902421", 25, 1.599e+1}' from '<brace-enclosed initializer list>' to 'Sales_data'

出现这个问题,是因为我在struct结构体里面,已经给予了变量的值
聚合类的作用是用特俗方式初始化变量的值
所以会出现无法初始化值的问题。

# include "iostream" 
//如何创建C++类 
class student{
public:
    char name;
    char sex;
void say(){
    std::cout << name << std::endl;
//访问类的成员 
int main(){
    //创建类的对象 
    student stu;
    stu.name = '香蕉哥';   //!@!@!@!@!
    std::cout << name << std::endl;  //!!!!!!!!!!!!!!!!!
//直接使用name,是会出现错误的。
//C:\C++\C++其他语言书\类和对象\c++类的定义和创建.cpp   
//[Error] 'name' was not declared in this scope
//因为name是student类中的变量,所以要使用name变量的话,就要
//用student创建对象,然后这个对象才能给这个变量赋值。
//[Warning] overflow in implicit constant conversion [-Woverflow]
//这种超越长度的话, 有可能会在输出控制台无法输出