If I've got a code such as this:
struct A virtual void f(void*) struct B : public A struct C : public B int primary()
I recieve a mistake that states that i'm attempting to do an invalid conversion from int to void*. Why can't compiler determine he needs to call B::f, since both functions are declared as virtual?
After reading through jalf's answer I went and reduced it even more. That one doesn't work too. Not so intuitive.
struct A struct B : public A int primary()
The short response is "because that's how overload resolution works in C++".
The compiler looks for functions F within the C class, and when it finds any, it stops the search, and attempts to choose a candidate among individuals. It only looks inside base classes if no matching functions were based in the derived class.
However, you are able to clearly introduce the bottom class functions in to the derived class' namespace:
struct C : public B using B::f // Add B's f function to C's namespace, permitting it to sign up in overload resolution
I had been a little doubtful about that certain, but indeed it doesn't compile. This is a simplified version from the code that demonstrates exactly the same problem.
class A virtual void f(void*) class B : public A int primary()
Well i believe to begin with u didn't know very well what virtual mechanism or polymorhism.once the polymorphism is accomplished only by utilizing object pointers.I believe u r a new comer to c++.without needing object pointers then there's no concept of polymorphism or virtual keyword use base class pointer and assign the preferred derived class objects into it.then cal and check out it.