考慮到這個代碼,我把一個bp在roll(int n)的末尾,並且我有值數組 中的數據,並且我在打印結束處放了另一個數據, array.Why我得到這個錯誤:CXX0069:錯誤:變量需要堆棧框架?錯誤:可變需要堆棧框架
die.h
#ifndef DIE_H
#define DIE_H
#include<iostream>
#include<time.h>
using namespace std;
class Die
{
private:
int number;
int values[6][2];
void roll();
public:
Die();
void Roll(int n);
int getNumber()const{return number;}
void printLastValue();
void printApearences();
~Die(){}
};
#endif
die.cpp
#include"die.h"
#include<iostream>
#include<time.h>
using namespace std;
Die::Die()
{
srand(static_cast<int>(time(NULL)));
number=0;
for(int j=0;j<6;j++)
{
values[j][0]=j+1;
values[j][1]=0;
}
}
void Die::roll()
{
number=1+rand()%6;
}
void Die::printLastValue()
{
cout<<number<<endl;
}
void Die::Roll(int n)
{
for(int j=0;j<6;j++)
{
values[j][0]=j+1;
values[j][1]=0;
}
for(int i=0;i<n;i++)
{
roll();
(values[number-1][1])++;
}
}
void Die::printApearences()
{
for(int i=0;i<6;i++)
{
cout<<values[i][0]<<" : "<<cout<<values[i][1]<<endl;
}
}
的main.cpp
#include"die.h"
#include<iostream>
using namespace std;
int main()
{
Die d;
d.Roll(5);
d.printApearences();
}
什麼行?請減少你的代碼。 – djechlin
爲我們提供了線索錯誤點 – pm100
在void Die :: Roll(int n)的末尾,值[6] [2]中有數據。但在無效Die :: printApearences()開始時,值[] [] – laura