Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Hidden Overloaded C++ Virtual Function
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Hidden Overloaded C++ Virtual Function




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.


Adin Hunter Baber



 _______________________________________________
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

References: 
 >Hidden Overloaded C++ Virtual Function (From: Nick Nallick <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.