I am beginner learning solidity....I m trying function overridding but I am unable to do it and I don't know why it shows error.
SPDX-License-Identifier: MIT
pragma solidity >=0.4.16 <0.9.0;
contract parent{
string public str = "Black";
function check() public view returns(string memory){
return str;
}
}
contract child is parent {
string public st = "Box";
function check() public view override returns(string memory){ // why this error?...plz help ;-;
return string(abi.encodePacked(str,st));
}
}
pragma solidity >=0.4.16 <0.9.0;
is your problem.
The keywords virtual
and override
were added in 0.6.0.
Try
pragma solidity >=0.6.12 <0.9.0;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.