个人技术分享

程序运行崩溃是常见问题,平时测试或者合并代码,发布版本做版主自检时经常遇到的问题。常见的崩溃原因有

        1  库与头文件不匹配

        不同的库调用了同一个头文件,头文件修改,库没有更新

#ifndef _MATCH_
#define _MATCH_

class match
{
public:
    match():a(0),b(0),c(0),test(0)
    {}

private:

    int a;
    int b;
    float c;

    //新增变量
    int test;
    
    //新增函数
    int set_params(int test);

}

#endif 

        2 内存访问越界

        多出现在vector中,索引越界,比如数据长度时0或空

int function(std::vector<int> &data)
{
    int temp = data[1];//如果数据为空则崩溃


    return 0;
}

        3 重复释放内存

        线程先创建并运行,线程内部指针参数为空未提前初始化

#include <thread>

vector<int> data;

int function()
{
    int temp = data[0];

}


void main()
{
    //先运行线程
    std::unique_ptr<thread> m_thread_ptr= std::make_unique<thread>(function);