Hello to everyone. I am looking at multiple inheritance in Solidity. I came across this example within their documentation, but it is not understandable enought for me.

Can someone explane this sentence in more detail:

The reason for this is that C requests X to override A (by specifying A, X in this order), but A itself requests to override X, which is a contradiction that cannot be resolved.

My question is why C requests X to override A, i.e. what this order of inheritance means exactly?

    pragma solidity ^0.4.0;

     contract X {}
     contract A is X {}
     contract C is A, X {}
  • This means nothing as it won't work (you'll get linearization error) contract C is X, A {}would be correct – Nico Vergauwen Nov 21 at 12:25
up vote 3 down vote accepted

After research I found:

With multiple inheritance, there is a issues comprising Diamond Problem. Solidity solves this problem like Python.

Here are two links describing this problem in detail: https://docs.python.org/2/tutorial/classes.html#instance-objects https://www.python.org/download/releases/2.3/mro/

So, the order of inheritance is important in order to avoid Diamond problem. Order should be: from classes on the top level of inheritance to the classes on lower levels

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.