访问违规是什么意思?
What does access violation mean?
我是c++的新手,不明白为什么我得到错误"访问违规读取位置"。下面是我的代码:
gdiscreen();
int startX = 1823 - minusX;
int startY = 915 - minusY;
for (int i = startX; i < startX + 61; i++)
{
for (int j = startY; j < startY + 70; j++)
{
Color pixelColor;
bitmap->GetPixel(i, j, &pixelColor);
cout << pixelColor.GetValue() << " ";
}
cout << endl;
}
gdiscreen()可以在这里找到:http://forums.codeguru.com/showthread.php?476912-GDI-screenshot-save-to-JPG
访问冲突或分段错误意味着您的程序试图访问未在作用域中保留的内存。
有几个例子如何实现这一点:
数组的左边界:
int arr[10];
for(unsigned char i=0; i<=10; i++) //Will throw this error at i=10
arr[i]=0;
注意:在上面的代码中,我使用unsigned char
进行迭代。Char是一个字节,所以unsigned char
是0-255。对于较大的数字,您可能需要unsigned short
(2字节)或unsigned int
(4字节)。
不小心使用指针而不是整数进行计算
int ah = 10;
int *pointer = &ah; //For some reason, we need pointer
pointer++; //We should've written this: (*pointer)++ to iterate value, not the pointer
std::cout<<"My number:"<<*pointer<<'n'; //Error - accessing ints address+1
我故意以宽泛的解释开始。你一开始就想知道什么是访问侵犯。在你的特定代码,我很确定你搞砸了i
和j
的边界。做一些std::cout
调试
相关文章:
- 这个语法std::class<>{}(arg1, arg2) 在C++中是什么意思?
- 标准 N3337 5.2.10 第 7 条中的C++"类型"是什么意思?
- "类模板示例<int>;"语句对 C++11 是什么意思?
- 线应该是什么意思
- "CID"在AT+HTTPPARA= "CID" ,1中是什么意思
- 表达式"b=(b-x)&x"是什么意思?
- 这个表达是什么意思?
- 此代码验证公式是什么意思?
- 跟踪日志中的T.11803()是什么意思?
- 这个额外的关键字在这个 c++ 类声明中是什么意思?
- * 和 ** 在 C++ 函数声明中是什么意思?
- _T("xyz")是什么意思?
- #define Dbg(fmt,..) (0) 是什么意思? 警告:表达式无效
- 这行代码到底是什么意思?
- 当我们说在执行程序时将操作系统的控制权传递给main()函数时,我们的意思是什么
- 这句话在c++中的意思是什么
- 这个typedef的意思是什么
- 这句话的意思是什么
- 意思是什么
- 这个句法的意思是什么?