J
Jochen Luig
Hi!
I think I don't grasp the concept of "new". I tried to create a
2-dimensional array using new (see code below). What I don't understand
is, why does the program below work while the lines I commented out and
labelled as "case 1" and "case 2" yield either a segmentation fault
(case 1) or a type conflict (case 2).
Thanks in advance
Jochen
Quelltext:
#include <list>
class SomeClass {
std::list<int> *list_array[10][10]; // case 2
// std::list<int> list_array[10][10]; // case 1
public:
SomeClass() {
int i,j;
for (i=0;i<=10;i++) {
for (j=0;j<=10;j++) {
list_array[j] = new std::list<int>;
// list_array[j] = *(new std::list<int>); // case 1
}
}
//list_array = new std::list<int>[10][10]; // case 2
}
};
main() {
SomeClass *x = new SomeClass();
}
I think I don't grasp the concept of "new". I tried to create a
2-dimensional array using new (see code below). What I don't understand
is, why does the program below work while the lines I commented out and
labelled as "case 1" and "case 2" yield either a segmentation fault
(case 1) or a type conflict (case 2).
Thanks in advance
Jochen
Quelltext:
#include <list>
class SomeClass {
std::list<int> *list_array[10][10]; // case 2
// std::list<int> list_array[10][10]; // case 1
public:
SomeClass() {
int i,j;
for (i=0;i<=10;i++) {
for (j=0;j<=10;j++) {
list_array[j] = new std::list<int>;
// list_array[j] = *(new std::list<int>); // case 1
}
}
//list_array = new std::list<int>[10][10]; // case 2
}
};
main() {
SomeClass *x = new SomeClass();
}