CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2000
    Location
    Lyon / France
    Posts
    352

    virtual inheritance, dominance and compiler warnings

    Hi all,

    I have a sample code that works as expected, but generates some compiler warnings.
    I can just do #pragma warning (disable:4250)
    and MSDN states that it is an informational warning,
    but I do not like warnings and I wonder if there's a way to avoid them.

    Here's the (simplified) stuff :
    class c {
    public:
    void s() {
    r();
    }
    virtual void r() {
    o();
    }
    virtual void o()=0;
    };

    class g : public virtual c {
    void o() {
    int zz=0;
    }
    };

    class l : public virtual c {
    void r() {
    int zz=1;
    }
    };

    class d : public l {
    };

    class e : public g, public d {
    };


    And here's the result :
    d:\visualcpp\test5\test.cpp(35) : warning C4250: 'e' : inherits 'l::r' via dominance
    d:\visualcpp\test5\test.cpp(26) : see declaration of 'r'
    d:\visualcpp\test5\test.cpp(35) : warning C4250: 'e' : inherits 'g:' via dominance
    d:\visualcpp\test5\test.cpp(20) : see declaration of 'o'

    When c::s calls r, l::r is called instead of c::r, exactly what I wanted.
    Some other classes will inherit from c, and c::r will be normally called here.

    I know all that may look a bit complicated, sorry for that. I think I need to read the Stroustrup book ;o)


    Thanks for any answer.


  2. #2
    Join Date
    Jan 2001
    Location
    Israel
    Posts
    226

    Re: virtual inheritance, dominance and compiler warnings

    You can derive r (for instance) in the 'e' and let it call l::r.

    like so:
    class e : public g, public d
    {
    public:
    void r() { l::r() };
    };



    _________________________________
    Assaf Lavie
    -- Rate if it helped --

  3. #3
    Join Date
    Apr 2000
    Location
    Lyon / France
    Posts
    352

    Re: virtual inheritance, dominance and compiler warnings

    Thanks for the answer

    This is a good idea for this simplified example, but rather pointless in my application.

    Method r() is used only internally by c and g, and should not appear in e. Class l "intercepts" this method only because it needs to add some stuff to it.
    And I have another class ee which will inherit from g and dd (dd is a "light" version of d, and will not inherit from c).

    Maybe there are some more constraints I forgot about, this application is getting very complex and I wish to leave the classes as independent (modular) as I can.There are several versions of the same classes, with the same interfaces, which must be interchanged without changing anything in the other classes.

    Pheeeew... I need some holidays...


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