class SimpleVariant
{
public:
SimpleVariant() { /*...*/ };
// ...
};
struct VariantBlock
{
int nRows, nCols;
vector<SimpleVariant> theData;
};
void dumbFunction(VariantBlock& theBlock, int nRows, int nCols)
{
// ...
cout << "theBlock.nRows= " << theBlock.nRows
<< ", theBlock.nCols= " << theBlock.nCols
<< ", theBlock.theData.size() " << theBlock.theData.size();
theBlock.theData.resize(nRows * nCols);
// throws Access Violation Exception
// ...
}
输出返回nRows = 61,nCols = 5,size()= 0,这正是它应该在那一点上,在引发访问冲突异常之前。Soul-crushing C++ std :: vector :: resize()访问冲突错误
我正在使用MSVC6,这显然不是最佳的,但在这一点上没有选择。
你在'SimpleVariant'中有什么类型的成员?你是否为'SimpleVariant'声明了复制构造函数和/或复制赋值运算符?如果是这样,他们做什么?您发布的代码没有任何明显的错误,尽管我最近没有使用VC6的经验。 – 2011-03-26 05:18:21
我没有定义它们。 – Doug 2011-03-26 05:19:36
这可能是坏的复制行为,正如詹姆斯指出的那样,但它也可能是程序中其他地方的内存破坏。 – templatetypedef 2011-03-26 05:20:46