CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2002
    Posts
    359

    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.
    Last edited by caperover2002; January 5th, 2006 at 09:29 AM.

  2. #2
    Join Date
    Apr 2005
    Location
    Norway
    Posts
    3,934

    Re: Interesting problem needs GURUS of managed/unmanaged C++ compliler

    Could you post some (complete) code that reproduces the error?

    - petter

  3. #3
    Join Date
    Oct 2002
    Posts
    359

    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".

  4. #4
    Join Date
    Apr 2005
    Location
    Norway
    Posts
    3,934

    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

  5. #5
    Join Date
    Oct 2002
    Posts
    359

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured