在函数中读取位置时引发的C ++代码调试异常(VS2015 Windows 8)Windows控制台应用程序 [英] C++ code debugging exception thrown when reading location in function (VS2015 Windows 8) Windows Console Application

查看:137
本文介绍了在函数中读取位置时引发的C ++代码调试异常(VS2015 Windows 8)Windows控制台应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好C ++程序员,我有一些代码可以构建但是在使用本地windows调试器进行调试时(逐行下行)我得到了这个中止程序的错误:



[code]在MonteCarloDemo.exe中0x01394FDA抛出异常:0xC0000005:访问冲突读取位置0xCCD6AACC。

如果有此异常的处理程序,程序可以安全地继续。[/ code ]¥


我检查了十六进制值,并将其追溯到此函数:



[code] double Mie :: GetCext(double lambda){

     int l;

     l = int(floor((lambda - LambdaMin)/ LambdaDiff));

     if(l< 0){

   &NBSP;&NBSP;&NBSP;   l = 0;

    }

     if(l> = LambdaNum){

   &NBSP;&NBSP;&NBSP;   l = LambdaNum - 1;

    }

    返回MD [l] .Cext;

} [/ code]



变量的一些解释:此函数是成员你可以看到三重班的。它旨在为光返回消光截面。以下是Mie类中的一些相关其他函数以及int
main()中函数的调用;
$


Mie类的成员函数:



[code] void Mie :: setLambdaMin(int value1){



     LambdaMin = value1;

$
}
$


void Mie :: setLambdaMax(int value2){



     LambdaMax = value2;
$


}
$


double Mie :: getLambdaMin(void){



    返回LambdaMin;



}

$


双Mie :: getLambdaMax(无效){



    返回LambdaMax;
$


}

双Mie :: getLambdaDiff(无效){



     LambdaDiff =(LambdaMax - LambdaMin)/(double)LambdaNum;



    返回LambdaDiff;

$
}

[/ code]

$
主要功能呼叫:

[代码]

       Mie m1;

       m1.setLambdaNum(100);

     numofLambda = m1.getLambdaNum();

   &NBSP; m1.setLambdaMin(650.0); //设置近红外范围

     m1.setLambdaMax(1350.0);

     double maxWaveL = m1.getLambdaMin();

     double minWaveL = m1.getLambdaMax();

     double lambdaDiff = m1.getLambdaDiff();

         double Cext = m1.GetCext(monochr_wavel);



[/ code]



如果有人可以请告诉我什么是抛出这个异常我会非常感激,因为它只是崩溃了debuggng ..非常感谢。

Hello fellow C++ coders, I have some code that builds but during debugging with local windows debugger (going down line by line) I get this error that aborts the program:

[code]Exception thrown at 0x01394FDA in MonteCarloDemo.exe: 0xC0000005: Access violation reading location 0xCCD6AACC.
If there is a handler for this exception, the program may be safely continued.[/code]

I checked the hexadecimal value and I have traced it to this function:

[code]double Mie::GetCext(double lambda) {
    int l;
    l = int(floor((lambda - LambdaMin) / LambdaDiff));
    if (l<0) {
        l = 0;
    }
    if (l >= LambdaNum) {
        l = LambdaNum - 1;
    }
    return MD[l].Cext;
}[/code]

Some explanation of the variables: This function is a member of the class Mie as you can see. It is meant to return an extinction cross section for light. Here are some of the associated other functions in the Mie class and the calls to the functions in int main();

Member functions of Mie Class:

[code]void Mie::setLambdaMin(int value1) {

    LambdaMin = value1;

}

void Mie::setLambdaMax(int value2) {

    LambdaMax = value2;

}

double Mie::getLambdaMin(void) {

    return LambdaMin;

}


double Mie::getLambdaMax(void) {

    return LambdaMax;

}
double Mie::getLambdaDiff(void){

    LambdaDiff = (LambdaMax - LambdaMin) / (double)LambdaNum;

    return LambdaDiff;

}
[/code]

Function calls in main:
[code]
       Mie m1;
       m1.setLambdaNum(100);
    numofLambda = m1.getLambdaNum();
    m1.setLambdaMin(650.0); //setting the near-IR range
    m1.setLambdaMax(1350.0);
    double maxWaveL = m1.getLambdaMin();
    double minWaveL = m1.getLambdaMax();
    double lambdaDiff = m1.getLambdaDiff();
         double Cext = m1.GetCext(monochr_wavel);

[/code]

If anyone can please tell me what is throwing this exception I would be extremely grateful as it is just crashing the debuggng.. many thanks.

推荐答案

首先,使用"插入代码块"发布代码时按钮。 这使得阅读和理解变得更加容易。

First, use the "Insert Code Block" button when posting code.  It makes it much easier to read and understand.

其次,您是否已经在调试器中逐行执行代码以确定变量(包括任何指针)在之前具有预期值发生异常?

Second, have you stepped through the code line by line in the debugger to determine that variables (including any pointers) have the expected values before the exception occurs?


这篇关于在函数中读取位置时引发的C ++代码调试异常(VS2015 Windows 8)Windows控制台应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆