Interesting problem needs GURUS of managed/unmanaged C++ compliler
Hi, all
I am running into a very interesting problem, which has been bothering me for a while.
I have a base class
class B
{
public:
virtual bool fun() =0;
}
and two derived classes
class A : public B
{
public:
virtual bool fun()
{
return false;
}
}
and
class C : public B
{
public:
virtual bool fun()
{
return false;
}
}
One thing that is very interesting is that if the following line appears anywhere in my managed code, whether it is executed or not,
A a;
the function C:fun's return value will become true.
What I am trying to understand is the difference it makes with or without "A a". Any hint or suggestion will be really appreciated!
Thanks.
Re: Interesting problem needs GURUS of managed/unmanaged C++ compliler
Could you post some (complete) code that reproduces the error?
- petter
Re: Interesting problem needs GURUS of managed/unmanaged C++ compliler
Actually I could not reproduce the problem in another context.
I am using Excel + COM + Managed C++ + Unmanaged C++. I cannot post a small piece of the code to reproduce the error.
What I am trying to understand is the difference it makes with or without "A a".
Re: Interesting problem needs GURUS of managed/unmanaged C++ compliler
Well, the difference is that with 'A a;' you're creating an instance of A using its default constructor. So, it really depends on what that constructor is doing.
- petter
Re: Interesting problem needs GURUS of managed/unmanaged C++ compliler
Hi, Peter,
Thanks for your help.
I cannot agree with you. Since "A a" only declares a local variable in some function, the classs will not be instantiated until "A a;" is executed at running time when its default constructor will be called.
In my case, no matter where I put " A a", C:fun() will fail. I suspect it relates the RTI table of the base classs B, but I am not sure of how.