Connecting Tech Pros Worldwide Help | Site Map

Hiding of Function in derived class

Dinesh Garg
Guest
 
Posts: n/a
#1: Jul 22 '05
Hi All,
Following program does not compile because Class B does not provide " int
foo(int) ". My Doubt here is why C++ hides the function in derived class
with same name ;infact derived class should have all public function of base
class unless signature is same in derived class. Can some one provide more
info on why C++ behaves this way ??

class A
{
public:
A() { }
char foo(char ch) { cout<<"\nfoo-Char\n"; return 0;}
int foo(int i) { cout<<"\nfoo-Int\n"; return 0;}
};

class B : public A
{
public:
int foo() { cout<<"\nOverloaded int foo in B !!\n"; return
0;}
};

int main()
{
B b;
b.foo(5);
return 0;
}


Thanks,
Dinesh


Sharad Kala
Guest
 
Posts: n/a
#2: Jul 22 '05

re: Hiding of Function in derived class



"Dinesh Garg" <gdinesh@lucent.com> wrote in message
news:ca47dv$734@netnews.proxy.lucent.com...[color=blue]
> Hi All,
> Following program does not compile because Class B does not provide " int
> foo(int) ". My Doubt here is why C++ hides the function in derived class
> with same name ;infact derived class should have all public function of base
> class unless signature is same in derived class. Can some one provide more
> info on why C++ behaves this way ??[/color]

A while ago we had a discussion on this topic. Here is the link -
http://tinyurl.com/3yv53.



Closed Thread