M
mario.rossi
Hi all,
I am trying to invoke the default constructor from another, parametrized,
constructor, but the default constructor doesn't get invoked at all, I saw.
Is this correct ISO C++ behaviour or my compiler has a ++bug (overflowing)?
struct Test {
int x;
int y;
//
Test() {
x=1;
y=2;
}
Test(int a) {
Test();
x+=a;
}
};
now, if I do:
Test Instance;
I will get 1 in x and 2 in y, as I expect.
But if I do:
Test Instance(3);
I will get garbage both in x and y, actually in x I will get garbage+3
(so to speak) and in y I will get garbage (the value that the stack
contained from previous use).
Ain't it possible to invoke the default constructor from another
constructor, or my compiler (VC++2005) has just another bug (TM)?
Thanks,
Mario
I am trying to invoke the default constructor from another, parametrized,
constructor, but the default constructor doesn't get invoked at all, I saw.
Is this correct ISO C++ behaviour or my compiler has a ++bug (overflowing)?
struct Test {
int x;
int y;
//
Test() {
x=1;
y=2;
}
Test(int a) {
Test();
x+=a;
}
};
now, if I do:
Test Instance;
I will get 1 in x and 2 in y, as I expect.
But if I do:
Test Instance(3);
I will get garbage both in x and y, actually in x I will get garbage+3
(so to speak) and in y I will get garbage (the value that the stack
contained from previous use).
Ain't it possible to invoke the default constructor from another
constructor, or my compiler (VC++2005) has just another bug (TM)?
Thanks,
Mario