CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2006
    Location
    Essen, Germany
    Posts
    1,344

    [RESOLVED] Deep inheritance and using directive

    Hi,

    is the following piece of code correct or am I doing something stupid?

    Code:
    struct A {};
    struct B {};
    struct C {};
    
    struct Interface
    {
       virtual ~Interface()
       {
       }
    
       virtual void func( const A& Obj ) = 0;
       virtual void func( const B& Obj ) = 0;
       virtual void func( const C& Obj ) = 0;
    };
    
    struct Default : Interface
    {
       virtual ~Default()
       {
       }
    
       void func( const A& Obj ) {}
       void func( const B& Obj ) {}
       void func( const C& Obj ) {}
    };
    
    struct Special : Default
    {
       // bring all func methods of Default into scope
       using Default::func;
    
       // specialize on A
       void func( const A& Obj )
       {
       }
    };
    I´ve got two compiler warnings:
    (1) Special::func( const A& ) hides virtual function Default::func( const B& Obj )
    (2) Special::func( const A& ) hides virtual function Default::func( const C& Obj )

    Is my compiler correct? From my understanding I´m telling it I want all func methods from the bases class to be available in Special.
    Last edited by GNiewerth; February 11th, 2009 at 12:23 PM. Reason: Typos fixed
    - Guido

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Deep inheritance and using directive

    The compiler warnings are wrong, and you can verify that by attempting to invoke the inherited func member functions that take a B and a C object by const reference respectively.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: Deep inheritance and using directive

    VS 2008 & Comeau say
    Even PC-Lint is happy!
    "It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
    Richard P. Feynman

  4. #4
    Join Date
    Aug 2008
    Posts
    112

    Re: Deep inheritance and using directive

    Adding DevC's mingW to make it more real
    hi,,,

  5. #5
    Join Date
    Nov 2006
    Location
    Essen, Germany
    Posts
    1,344

    Re: Deep inheritance and using directive

    That´s what I already suspected. I ran it in Dinkumware´s online EXAM using different compilers and none showed any warnings.
    Thanks to all of you for confirming this.
    - Guido

  6. #6
    Join Date
    Nov 2007
    Posts
    74

    Re: Deep inheritance and using directive

    That can be changed anytime due to bugs/outofdate versionxxxx

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