我对瓦兰有意见,
我创建了这个类:
class shop {
private:
vector<vector<string> > products_;
public:
shop(string ProductFile);
FindMinPrice(string product);
}
//method in the cpp file
vector<string> shop::FindMinPrice(string product){
string ProductName=(string)products_[0][0];
}我没有编写完整的代码,但是它在GCC编译器中工作得很好。当我运行val研检查时,它会显示:大小为8的无效读取,在eclipse中,它将我发送到ProductName行。
这个设计有什么问题?而GCC又是如何编译和运行的,而瓦莱金却崩溃了?
谢谢。
发布于 2013-11-24 23:40:06
您的向量的products_向量似乎是空的,这意味着元素products_[0][0]的访问是未定义的行为。
关于未定义行为的不幸之处在于,您的程序可能看起来工作正常,甚至可以在没有任何明显问题的情况下完成。
发布于 2013-11-24 23:44:24
https://stackoverflow.com/questions/20182554
复制相似问题