Re: Hidden Overloaded C++ Virtual Function
Re: Hidden Overloaded C++ Virtual Function
- Subject: Re: Hidden Overloaded C++ Virtual Function
- From: Adin Hunter Baber <email@hidden>
- Date: Sat, 31 Dec 2005 07:56:56 -0600
On 2005 Dec 30, at 1:12 PM, Nick Nallick wrote: There's probably something subtle here that I don't understand, but can somebody tell me why gcc4 is telling me that A::foo(a) is hidden by B::foo(b) when I comment out B::foo(a) below? This seems like an overenthusiastic warning to me.
Thanks, Nick
warning: 'virtual void A::foo(a)' was hidden warning: by 'virtual void B::foo(b)'
struct a { int i; };
struct b { double x; };
class A { virtual ~A() {}; virtual void foo(a) {}; virtual void foo(b) {}; };
class B : public A { // virtual void foo(a) {}; virtual void foo(b) {}; };
Others have pointed out why you are having a problem. Here's away to avoid the problem:
class A { public: virtual ~A(); void foo(a); void foo(b); private: virtual void foo_a_impl(a); virtual void foo_b_impl(b); };
void A::foo(a) { foo_a_impl(a); } void A::foo(b) { foo_b_impl(b); } class B { public: // ... private: virtual void foo_a_impl(a); virtual void foo_b_impl(b); };
Class B will inherit the public foo()'s, and will automatically call the correct private virtual implementation functions. You no longer need to worry about the hidden functions issue.
|
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden