Click to See Complete Forum and Search --> : Interesting problem needs GURUS of managed/unmanaged C++ compliler


caperover2002
January 5th, 2006, 08:31 AM
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.

wildfrog
January 5th, 2006, 08:50 AM
Could you post some (complete) code that reproduces the error?

- petter

caperover2002
January 5th, 2006, 09:20 AM
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".

wildfrog
January 5th, 2006, 09:30 AM
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

caperover2002
January 5th, 2006, 09:48 AM
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.