How to Unhide an Inherited
Function
Date: Mon, 13 Aug 1999 08:57:20 -400
(copied and edited from a message posted on borland.public.cppbuilder.language
)
Q: When I have the following class structure:
typedef
unsigned long tA;
typedef unsigned char tB;
class cA {
public:
void Method(tA par);
};
class cB : public cA {
public:
void Method(tB par);
};
A cB instantiated object requires the use of cA::Method
when passing a tA type parameter. How can I call
Method without specifying cA:: when passing a tA type
parameter?
A: In your derived class add this statement:
using cA::Method;
Like this:
typedef
unsigned long tA;
typedef unsigned char tB;
class cA {
public:
void Method(tA par);
};
class cB : public cA {
public:
void Method(tB par);
using cA::Method;
};
void cA::Method(tA par) {
cout << "cA::Method, par = "
<< par << endl;
cout << " sizeof(par) = "
<< sizeof(par) << endl;
}
void cB::Method(tB par) {
cout << "cB::Method, par = "
<< par << endl;
cout << " sizeof(par) = "
<< sizeof(par) << endl;
}
#pragma argsused
int main(int argc, char* argv[])
{
cB obj;
tA a = 0x1000 + 'A';
tB b = 'B';
obj.Method(a);
obj.Method(b);
return 0;
}
Generates this output:
cA::Method,
par = 4161
sizeof(par) = 4
cB::Method, par = B
sizeof(par) = 1
Popular C++ topics at The Database Managers:
|