I've the next code:

#include <iostream>

class Grandma
{
public:
    virtual void foo() = 0;
};

class Mom : public Grandma{};

class Dad
{
public:
    void foo() { std::cout << "dad's foo impl"; }
};

class Me : public Mom, public Dad{};

int main()
{
    Me m;
    m.foo();
}

and becoming : cannot instantiate abstract class

I understand what this error means, I understand I can not instantiate Grandmother due to pure-virtual.

Why can't I instantiate Me, when compiler knows I'm based on Mother and Father and Father has foo implemented?

I understand I'm able to fixed it with the addition of foo into Me and within it call e.g. Dad::foo, however i am afraid it's not solution for my situation.

Could it be really essential to have virtual method implementation between its declaration and instantiated object (when crossing "class hierarchy graph")? See ASCI graph

    A
    |
B1  B2
  \ |   
   C1  C2
    | /
    |/
    D
    |
    E

When I wish to instantiate E and also have virtual declaration inside a, the only method to allow it to be run would be to define it inside a, B2, C1, D or E? together with just when was virtual declaration in C2 best way would be to define it in C2, D or E?

I understand this might be silly question, however i were built with a loooong day and may not think any longer.

Please, don't answer simply with - "It's not possible", but consider adding logic behind why not.

Thanks!

EDIT -- foo() in Dad is obviously shouldn't be private

There's no relation between Dad class and Grandma class. Dad and Grandma are two different classes. Considering that the technique in Dad isn't regarded as an implementation from the pure virtual method in Grandma and needs to be implemented within the Me class.

Whenever you be a consequence of an Abstract class(class that contains atleast one pure virtual function) the drawing class must override and implement ALL the pure virtual member functions from the Base Class. Otherwise, the drawing class becomes Abstract too, same is applicable towards the classes drawing in the derived class further lower the hierarchy.

Regrettably you are right you need to implement the virtual method within the path between original declaration and final instantiated object. Objects multiply inherited in can't implement that interface.

So in the question it may sound like you are attempting to implement a parent or gaurdian interface inside a child class by getting in the implementor. Rather than that approach, have you consider rather getting parents class delegate the job to some strategy pattern after which choose the correct strategy inside your child class. You'll be able to still compose implementations together and do not need to bother about the numerous difficulties of multiple inheritance.

You're factual that an online function is just overridden by implementations supplied by classes getting (potentially through several layers) in the class in which the virtual function is initially declared.

However, based on what you're really attempting to accomplish, Sister Class Delegation may what you would like. Essentially, you are able to declare virtual functions inside a base present with both Grandmother and Father ('Person'?) and Grandmother can call individuals functions even when only Father offers an implementation when you are utilizing a Me object. Despite the fact that Grandmother knows nothing about Father, if you use virtual inheritance any subclasses one last class pulls in may be used to satisfy virtual functions in the virtual base class.