cpp运行时报错terminate called after throwing an instance of std__bad_alloc

⌚Time: 2023-05-01 23:19:36

👨‍💻Author: Jack Ge

程序运行时发生错误


terminate called after throwing an instance of 'std::bad_alloc'

  what():  std::bad_alloc

代码类似于




#include <vector>

using namespace std;

class CA{

public:

    CA();

    CA(vector<int>);

private:

    vector<int> va;

};

CA::CA(){

}

CA::CA(vector<int> vb):va(va){//错误地方,写错变量,用自己vector变量初始化自己



}

int main(){

    CA ca({1,2});

    return 0;

}


初始化成员变量地方写错了vector容器变量名字,改成


CA::CA(vector<int> vb):va(vb){



}