Chapter 4: constructors: contract should be marked abstract #191
-
Thanks for the video. I was going through solidity doc to learn about constructors : // SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;
contract Parent {
string name;
uint age;
// If the base constructors have arguments, derived contracts need to specify all of them.
constructor(string memory _name, uint _age) {
name = _name;
age = _age;
}
}
// the arguments can be specified either
// by declaring an abstract
abstract contract Child3 is Parent {}
// and have the next concrete derived contract initialize it.
contract Child6 is Child3 {
constructor() Child3("Ademola", 90) {}
} I found these answers, Stackoverflow answer and Ethereum StackExchange answer, but they are not helpful. There was no error when I copied the code in Solidity doc. I'm sorry about how the code looks like but my repo contains the exact code. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
The Parent contract has a constructor but Child3 (which inherits Parent) is missing this required implementation thus required to be marked as abstract. Child6 is now inheriting from Child3 which is an abstract class, thus required to be marked as abstract OR implement the required unimplemented functions like this: As any contract in Solidity that has at least one unimplemented function will be considered as abstract. |
Beta Was this translation helpful? Give feedback.
-
@coinfeigm Thanks, thank you very much. I didn't notice |
Beta Was this translation helpful? Give feedback.
The Parent contract has a constructor but Child3 (which inherits Parent) is missing this required implementation thus required to be marked as abstract.
Child6 is now inheriting from Child3 which is an abstract class, thus required to be marked as abstract OR implement the required unimplemented functions like this:
contract Child6 is Child3 { constructor() Parent("Ademola", 90) {} }
As any contract in Solidity that has at least one unimplemented function will be considered as abstract.