B
Bubba
Greetings to all,
here's the thing:
struct foo {
string a;
int b;
foo () {}
foo (string a, int b);
};
struct bar {
foo *data;
bar () {
bar (int m, int n)
void add (foo S, int i, int j);
};
foo::foo (string a, int b) {
foo::a = a;
foo::b = b;
}
bar::bar (int m, int n) {
foo* data = new foo[m*n*4];
}
Now I have a problem with function add, where I should access particular
element in data array of foo's and assign values from parameter, but don't
know exactly how. This doesn't work since it throws segmentation fault:
bar::add (foo S, int i, int j) {
data[(i*j*4)-].a = S.a;
data[(i*j*4)-].b = S.b;
}
What's the proper way to do that? I require array of foo's in the bar's
constructor.
Best regards,
here's the thing:
struct foo {
string a;
int b;
foo () {}
foo (string a, int b);
};
struct bar {
foo *data;
bar () {
bar (int m, int n)
void add (foo S, int i, int j);
};
foo::foo (string a, int b) {
foo::a = a;
foo::b = b;
}
bar::bar (int m, int n) {
foo* data = new foo[m*n*4];
}
Now I have a problem with function add, where I should access particular
element in data array of foo's and assign values from parameter, but don't
know exactly how. This doesn't work since it throws segmentation fault:
bar::add (foo S, int i, int j) {
data[(i*j*4)-].a = S.a;
data[(i*j*4)-].b = S.b;
}
What's the proper way to do that? I require array of foo's in the bar's
constructor.
Best regards,