小编use*_*807的帖子

c ++ vector在try-catch中没有声明

这是我的代码片段,显示try-catch块中的向量声明:

try {
vector<opClass> op;
}
catch (bad_alloc xa) {
    cout << "\nAllocation failure!\n";
    return 1;
};
//...
//...
op.push_back(<input some stuff>) //error c2065: op undeclared identifier
Run Code Online (Sandbox Code Playgroud)

奇怪的是,当我将我的矢量声明放在try-catch块之外时,错误消失了.这与STL中如何定义向量有关吗?我认为将这个声明放在try-catch块中是好的做法,因为向量是动态数组?

c++ vector try-catch undeclared-identifier

-2
推荐指数
1
解决办法
936
查看次数

标签 统计

c++ ×1

try-catch ×1

undeclared-identifier ×1

vector ×1