Hiding of Function in derived class

D

Dinesh Garg

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
 
S

Sharad Kala

Dinesh Garg said:
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 ??

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top