正直なところ、これについて何か間違っているとは言えません。私は同様の問題を持つスレッドを読んだことがありますが、人々はメモリや物事の割り当てを扱っています。これはこれまでプログラマーとしての範囲を超えていて、私のプログラムはそれほど複雑ではありません。 0x00363A09で未処理の例外が発生しました。スタッククッキーインストルメンテーションコードがスタックベースのバッファオーバーランを検出しました
int main() {
double input[5] = { 5.0, 6.0, 8.0, 4.3, 5.6 };
GradeBook test(sizeof(input), input);
test.bubbleSort();
test.printAll();
return 0;
};
は、これらは私のプライベートなデータメンバー私の評定表のクラスのための
const static int gradeBookSize = 6;
int classSize;
double grades[gradeBookSize];
bool insertionSorted = false; //simply for efficency
bool bubbleSorted = false;
コンストラクタです
GradeBook(int inputSize, double inputGrades[]) {
classSize = inputSize;
for (int i = 0; i < classSize; i++) {
grades[i] = (inputGrades[i]);
}
for (int i = classSize; i < sizeof(grades); i++) {
grades[i] = 0;
}
}
そして最後に、アイブ氏は、実際に私のmain()メソッドで使用される2つのメソッド
void bubbleSort() {
//sorts grades in descending order using bubblesort algorithm
bool sorted = false;
while (!sorted) {
for (int i = 0; i < (sizeof(grades) - 1); i++) {
if (grades[i] < grades[i + 1]) {
double tmp = grades[i + 1];
grades[i + 1] = grades[i];
grades[i] = tmp;
}
}
bool test = false;
for (int i = 0; i < sizeof(grades) - 1; i++) {
if (grades[i] < grades[i + 1]) test = true;
}
sorted = !test;
}
bubbleSorted = true;
insertionSorted = false;
}
void printAll() {
for (int i = 0; i < sizeof(grades); i++) {
cout << grades[i] << "\t";
}
cout << endl;
}
私たちは私のデバッグ出力を持って再、私はこの
The thread 0x3378 has exited with code 0 (0x0).
Unhandled exception at 0x0130FC38 in CS260_Project4_James_Casimir.exe:0xC00001A5: An invalid exception handler routine has been detected (parameters: 0x00000003).
CS260_Project4_James_Casimir.exe has triggered a breakpoint.
Run-Time Check Failure #2 - Stack around the variable 'test' was corrupted.
Unhandled exception at 0x00363A09 in CS260_Project4_James_Casimir.exe: Stack cookie instrumentation code detected a stack-based buffer overrun.
Unhandled exception at 0x00363A09 in CS260_Project4_James_Casimir.exe: Stack cookie instrumentation code detected a stack-based buffer overrun.
Unhandled exception at 0x00363A09 in CS260_Project4_James_Casimir.exe: Stack cookie instrumentation code detected a stack-based buffer overrun.
The program '[7400] CS260_Project4_James_Casimir.exe' has exited with code 0 (0x0).
'のはsizeof(グレード)' - あなたはこれがどうなるかだと思いますか?それはあなたが期待するものではありません。実際、 'sizeof(input)'のように、どこで使っても間違って使います。 – PaulMcKenzie
@PaulMcKenzie私はそれがjavaの.size()関数に似ていると思った。これは本当に何をしてくれるのですか? –
'sizeof(T)'は、 'T'型が配列内の項目の数ではなく**バイト**の数を返します。 C++はJavaではありません - JavaをモデルとしてC++を試してみませんか? – PaulMcKenzie