このプログラムはコンパイルされますが、実行されません。実行するたびに、私はこれを受け取ります:これはコンパイルされますが、実行されません。何か案は?
"Assignment3.1.exeの0x00D761EEで処理されない例外:0xC0000005:アクセス違反の読み取り場所0x00000000。"
私は間違っていますか?
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
//Function Prototype
void getSize(int *);
float *getValues(int *);
float getMax(const float *, const int *);
int main()
{
float * ptData = nullptr;
int * ptr = nullptr;
int num;
getSize(&num);
float values = *getValues(&num);
float max = getMax(ptData, &num);
return 0;
}
//*******************************************************************************************************
void getSize(int * ptr)
{
cout << "Please enter a size to the array: ";
cin >> *ptr;
while (*ptr <= 1)
{
cout << "!!!Error: an array's size cannot be less than or equal to 1!\n";
cout << "Please enter a size to the array: ";
cin >> *ptr;
}
}
//*******************************************************************************************************
float * getValues(int * ptr)
{
float * ptData = new float[*ptr];
cout << "Please enter all values of the array: \n";
for (int count = 0; count < *ptr; count++)
{
cout << "Value " << (count + 1) << ": ";
cin >> ptData[count];
}
delete[] ptData;
ptData = 0;
return ptData;
}
//*******************************************************************************************************
float getMax(const float * ptData, const int * ptr)
{
float highest;
highest = *ptData;
for (int count = 1; count < *ptr; count++)
{
if (ptData[count] > highest)
highest = ptData[count];
}
return highest;
}
*私は間違っていますか?* - ポインタの代わりに 'std :: vector'を使うことを拒否しました。 – PaulMcKenzie
2つ目は、デバッガで問題を突き止めて原因を突き止めることができませんでした。 0x00000000のアドレスは、ヌルポインタにアクセスすることを意味します。デバッガを使用すると、具体的にどこに何があったのかを特定するのに役立ちます。そのデバッガを使用することを習得していない場合は、今すぐ学習を開始するのに最適な時間です。 –
* Assignment3 * - これが本当にC++コースのためにあなたに与えられた割り当てであれば、これから遠ざかります。誰もこの方法でC++プログラムを書く人はいません。 – PaulMcKenzie