I have been testing this code for about an hour now, and still do not get why it fails. When I try it in a test program it works, but in the normal program it fails.
test code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
class a {
public:
string c;
a() {
string a[]={"hello", "hi"};
c=a[1];
}
};
int main() {
a h;
cout<<h.c; //in test code, it works
//in actual program the same concept fails
}
in the test the output is "hi", but in the normal program it is a blank line. The test code uses has exactly the same semantics as the test code:
1) in class constructor assign string variable to member of array
2) instantiate new class
3) output variable
As I explained above, in the test unit the program outputs "hi", while in the normal program it outputs a blank line.
If you simplify code until an issue no longer occurs with it, you've very likely removed the source of the issue. How, then, are we supposed to advise you about the error when the code provided doesn't produce it?
Ah, I seemed to have left out a very important detail (very sorry). Still od not understand why it does not work though. New test unit code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
class a {
public:
string c;
int b;
a(int p) {
string a[]={"hello", "hi"};
c=a[1];
b=p;
}
a() { a(0); }
};
int main() {
a h;
cout<<h.c; //in test code, it works
//in actual program the same concept fails
}