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
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