-
February 11th, 2009, 12:18 PM
#1
[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
-
February 11th, 2009, 12:23 PM
#2
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.
-
February 12th, 2009, 05:04 AM
#3
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
-
February 12th, 2009, 05:18 AM
#4
Re: Deep inheritance and using directive
Adding DevC's mingW to make it more real
hi,,,
-
February 12th, 2009, 05:54 AM
#5
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
-
February 12th, 2009, 05:59 AM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|