Q on name hiding

Deepak Shetty deepak@sonysard.co.in
Thu Sep 14 04:57:00 GMT 2000


Hi, folks
I tried to compile the foll. piece of code on my Redhat Linux release 6.2 Kernel Ver 2.2.14-5.0 using g++;
g++ version is...
egcs-2.91.66
===================================================================================

#include <iostream.h>

class B
{
public:
    void foo( char y)
    {
        cout << "In Base class, foo(char) fn" << endl;
    }

};

class D : public B
{
public:
    void foo( int d )
    {
        cout << "In Derived class, foo( int) fn " << endl;
    }
    using B::foo;
};

void main()
{
D d;
d.foo( 'A' );

}

I am basically using the statement "using B::foo", in order to bring the base class version of foo( char ) in the derived scope, and to avoid name hiding, BUT i get the foll. error, can some one help!

tp.cc:21: cannot adjust access to `void B::foo(char)' in `class D'
tp.cc:17:   because of local method `void D::foo(int)' with same name

The whole purpose of this is to get access to foo( char ), but the error seems to be neglecting the overloading concept of C++ as it just goes  on the basis of name and hence rejects the overloaded version of foo.

Thanx,
deepak



More information about the Gcc-help mailing list