이 문제가 발생하여 처리 할 수 없습니다. 모든 제안을 부탁드립니다. Results.h다른 cpp 파일의 함수에서 (.h 파일에 정의 된) 구조체를 반환하는 방법은 무엇입니까?
#ifndef RESULTS_H
#define RESULTS_H
struct Results
{
double dOptSizeMWh;
double dOrigSOCFinal;
double dManiSOCFinal;
};
#endif
및 Deterministic.h의 "결정 성"기능의 일반적인 정의 : I 헤더 파일에 정의 된 구조는 이하대로
#ifndef DETERMINISTIC_H
#define DETERMINISTIC_H
Results Deterministic(int,int,int,double,double); //Deterministic(int nNoMonth, int nNOWind, int nWindLength, double dPreviousSizeMWh, double dPreviousSOC)
#endif;
이 기능의 구현 Deterministic.cpp :
#include "Results.h"
Results Deterministic(int nNoMonth, int nNOWind, int nWindLength, double dPreviousSizeMWh, double dPreviousSOC)
{
// returns number of rows and columns of the array created
struct Results sRes;
sRes.dOptSizeMWh = -1.0; // for the optimal size of battery in MWh
sRes.dOrigSOCFinal = -1.0; // for the SOC at the end of the window
sRes.dManiSOCFinal = -1.0; // this is set to 0.0 if final SOC is slightly below 0
//...........................////
// OTHER Calculation .......////
//...........................////
return sRes;
}
마지막으로 필자는 결정 성 함수라고하는 주 파일을 사용하며 결과 구조 인 main.cpp :
#include <Results.h>
#include <Deterministic.h>
using namespace std;
int main()
{
int nNoMonth = 1; // the month that we want to use in the input
int nWindLength = 1; // length of window, hour
int nNODays = 1; // number of days that we want to repeat optimization
struct Results dValues;
double **mRes = new double*[nNODays * 24/nWindLength];
for (int i = 0; i < nNODays * 24/nWindLength; ++i) mRes[i] = new double[3];
for (int i = 0; i < nNODays * 24/nWindLength; i++)
{
if (i == 0)
{
dValues = Deterministic(nNoMonth, i, nWindLength, 0.0, 0.0);
}else
{
temp0 = *(*(mRes+i-1)); double temp1 = *(*(mRes+i-1)+1); double temp2 = *(*(mRes+i-1)+2);
if (temp2 == -1.0) {dValues = Deterministic(nNoMonth, i, nWindLength, temp0, temp1);}
else {dValues = Deterministic(nNoMonth, i, nWindLength, *(*(mRes+i-1)), *(*(mRes+i-1)));}
}
*(*(mRes+i)) = dValues.dOptSizeMWh;
*(*(mRes+i)+1) = dValues.dOrigSOCFinal;
*(*(mRes+i)+2) = dValues.dManiSOCFinal;
}
이들은 문제를 정의하는 Deterministic.cpp 및 main.cpp의 코드 중 일부에 지나지 않습니다. 첫 번째 루프는 아무런 문제없이 잘 진행되지만 두 번째 루프 이상에서는이 오류가 발생합니다. "R6010 - abort()가 호출되었습니다" 이 오류는 main.cpp에서 발생합니다. call if 문에서 결정적인 함수.
디버거를 사용하여 충돌을 조사하십시오. –
Andrew, 답변 해 주셔서 감사합니다. 나는 시도했지만 근본 원인을 정확히 알려주지 않았다. –