ConsoleApplication4.exe已停止工作.Windows将关闭该程序并通知是否有可用的解决方案

ConsoleApplication4.exe has stopped working. Windows will close the program and notify if a solution is available

本文关键字:是否 通知 解决方案 程序 停止工作 exe Windows ConsoleApplication4      更新时间:2023-10-16

我是c++和Visual Studio的新手。我试图在Visual Studio 2012中运行和调试代码。但是当代码需要一些更复杂的计算时,VS就像下面的例子一样崩溃了。编译后,当我点击开始没有调试,我得到一个弹出窗口显示上述消息。最后显示调试和关闭程序两个选项。当我点击调试时,它说"控制台application4.exe[5844]中发生了未处理的win32异常"。我不明白这是怎么回事。当我尝试运行一些简单的程序,如std::cout << "something";,它显示正确的消息。

// ConsoleApplication4.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "tbb/blocked_range.h"
#include "tbb/tbb.h"
#include <stdio.h> 
#include <math.h>
#include <iostream>
#include "tbb/parallel_for.h"
using namespace tbb;
#define PI 3.14159265
class CL
{
    double * rangeOne;
    double * rangeTwo;
public:
    CL(double * rangeOne, double * rangeTwo) {}
    void operator()(blocked_range<size_t>& r)
        const
    {
        for (size_t i = r.begin(); i != r.end(); ++i)
        {
            rangeOne[i] = sin(i*PI / 180);        
            rangeTwo[i] = cos(i*PI / 180);            
        }
    }

};
int _tmain(int argc, _TCHAR* argv[])
{
    double * u = new double[10];
    double * p = new double[10];
    parallel_for(blocked_range<size_t>(0, 10), CL(u, p));
    return 0;
}

This:

CL(double * rangeOne, double * rangeTwo) {}

不初始化你的类变量。它什么也不做。什么也没有。

应该是:

CL(double * rangeOne, double * rangeTwo) : rangeOne(rangeOne), rangeTwo(rangeTwo) {}

但是请帮自己一个大忙,利用这个错误来学习如何使用调试器。这不会是你一生中遇到的最后一个错误。

通过F10一步一步地找出异常点,并检查出哪一步异常即将到来