Const parameter at constructor causes stackoverflow
- by Luca
I've found this strange behavior with VS2005 C++ compiler. Here is the situation:
I cannot publish the code, but situation is very simple.
Here is initial code: it work perfectly
class Foo {
public:
Foo(Bar &bar) { ... }
}
The constructor implementation stores a reference, setup some members... indeed nothing special.
If I change the code in the following way:
class Foo {
public:
Foo(const Bar &bar) { ... }
}
I've added a const qualifier to the only constructor routine parameter.
It compiles correctly, but the compiler outputs a warning saying that the routine Foo::Foo will cause a stackoverflow (even if the execution path doesn't construct any object Foo); effectively this happens.
So, why the code without the const parameter works perfectly, while the one with the const qualifier causes a stackoverflow? What can cause this strange behavior?