CRYPTO NEWS

Brazilian toddler makes over 6,500% profit on her first Bitcoin holding

A father’s gift of 1 BTC (roughly $915.80) to his newborn daughter back in 2017 is now worth more than $60,000.

C++ (or generally OOP) inheritance in Solidity

In Solidity, when one does inheritance, the two contracts share state. Some pseudocode, contract A { uint myVar = 1 setVar() {myVar = 3} } contract B is A { myVar = 2 } If I deploy A, A.myVar = 1. If I deploy B and then call A.setVar(), B.myVar = 3 (and not 2).::Listen

In Solidity, when one does inheritance, the two contracts share state. Some pseudocode,

contract A { uint myVar = 1 setVar() {myVar = 3} }  contract B is A { myVar = 2 }  

If I deploy A, A.myVar = 1. If I deploy B and then call A.setVar(), B.myVar = 3 (and not 2).

So clearly, inherited contracts share state in Solidity.

In C++, inherited classes do not share state. If you want this kind of shared state functionality, you would need to use the “virtual” key word to reference data in memory (independent of classes).

How can I get “C++ inheritance” functionality in Solidity? For example, if I deploy A, then deploy B, B inherits the functionality of A (namely setVar()) but they do not share state, so A.myVar = 1 and B.myVar = 2 after deployment of both contracts. If I called A.setVar(), B.myVar would still be 2.

Brazilian toddler makes over 6,500% profit on her first Bitcoin holding

Shopping cart
There are no products in the cart!
Continue shopping
0