Я определил класс, и одна из закрытых переменных с именем «Path» указывает на логический массив. Определение класса:
class Elevator {
public:
Elevator();
int Solve();
void PrintPath();
private:
int lim;
int n;
int* w;
int* v;
int** DP;
bool* Path;
};
И конструктор:
Elevator::Elevator ()
{
cout << "\n\tWeight limit: "; cin >> lim;
cout << "\n\tNumber of people: "; cin >> n;
w = new int [n + 1];
v = new int [n + 1];
cout << "did w and v.\n";
cout << "Path.\n";
Path = new bool [n + 1]; // HERE
cout << "Does the code get here?";
DP = new int* [n + 1];
for (int i = 1; i <= n; i++)
{
DP[i] = new int [lim + 1];
for (int j = 0; j <= lim; j++)
DP[i][j] = 0;
}
}
Согласно инструкциям печати, он работает до строки, помеченной комментарием "\ ЗДЕСЬ".
$ ./a.out
Weight limit: 50
Number of people: 3
did w and v.
Path.
Segmentation fault: 11
Я не знаю, в чем проблема, потому что она работает для других указателей на целые числа.