【发布时间】:2019-06-27 17:46:50
【问题描述】:
老实说,我什至不知道我现在想要做什么。但是在我让这个函数工作之前我不能更进一步,它每次都会抛出那个异常,出了什么问题?异常是“CS 330 19S、P1、Calvert、程序 1.exe 中 0x0F61CAB6 (ucrtbased.dll) 处的未处理异常:将无效参数传递给认为无效参数致命的函数”
#include<iostream>
#include<vector>
#include <fstream>
using namespace std;
struct Kinematic {
vector<vector<float>> position;
float orientation;
vector<vector<float>> velocity;
float rotation;
};
struct StreeringOutput {
vector<vector<float>> linear;
float angular;
};
void update(StreeringOutput steering, float time, Kinematic k)
{
for (int i = 0; i < 100; i++)
{
for (int j = 0; j < 100; j++)
{
k.position[i][j] += k.velocity[i][j] * time +
0.5*steering.linear[i][j] * time*time;
//the above command is where it throws the exception
k.velocity[i][j] += steering.linear[i][j] * time;
}
}
k.orientation += k.rotation*time + 0.5*steering.angular*time*time;
k.rotation = steering.angular*time;
}
int main()
{
int test;
Kinematic kin;
StreeringOutput steering;
float time = 0.0;
ofstream outfile;
outfile.open("Output.txt");
for (int i = 0; i < 100; i++)
{
update(steering, time, kin);
time += 0.5;
}
cin >> test;
return 0;
}
【问题讨论】:
-
请在此处发布minimal reproducible example 重现问题。
-
您似乎从未在
vectors 中分配空间,因此对它们进行索引是非法操作。使用调试器进行调查。 -
改用
steering.at(i).at(j),然后修复异常。 -
也许真正的代码已经被简化掉了,但是更新 by-value
kparameter 是没有用的。
标签: c++ parameter-passing 2d-vector