overloaded function with mismatching parameters
class A
{ public:
void g(int i)
{ cout<<"in a";
}
{ public:
void f()
{ cout<<"in b";
}
{ B b;
b.f(); //vl call b::f()
b.g(4); //vl call a::g()
class A
{ public:
void f(int i)
{ cout<<"in a";
}
{ public:
void f()
{ cout<<"in b";
}
{ B b;
b.f(); //vl call b::f()
b.f(4); //bt here errror occurs not a matching protoype...
parameters)?
{ public:
void g(int i)
{ cout<<"in a";
}
};
class B:public A { public:
void f()
{ cout<<"in b";
}
};
int main() { B b;
b.f(); //vl call b::f()
b.g(4); //vl call a::g()
}
but class A
{ public:
void f(int i)
{ cout<<"in a";
}
};
class B:public A { public:
void f()
{ cout<<"in b";
}
};
int main() { B b;
b.f(); //vl call b::f()
b.f(4); //bt here errror occurs not a matching protoype...
}
So,can we overload function in inheritance(which vary in parameters)?
Yes ,we can use overload function but actual terminology its called overriding here instead of b.f(4); you will write b.A::f(4);
ReplyDeletesince this is the generic syntax and you can use this over any condition.
@Mufaddal yes it can be accessed the way you have mentioned or we have to declare same function with matching parameters in class B also..:)
ReplyDelete