Solidity: constructor, internal, and why not external?

Created on 26 Oct 2017  路  9Comments  路  Source: ethereum/solidity

Remix tells me: Constructor must be public or internal

If i make internal I get: This contract does not implement all functions and thus cannot be created. ...

What's the purpose and how to use an internal constructor ?

Why must a constructor be public instead of external?

documentation

All 9 comments

See #2638. Basically it allows an abstract contract to have a constructor, which is used by the child.

Thanks, that's helpful and makes sense.

Any explanation for:

Why must a constructor be public instead of external?

Idea-wise, if a constructor was allowed to be external then that would prevent inheritance? (There's an issue here somewhere like final in Java.)

Hm, I cannot recall any particular reason, but yes, inheritance would be a problem with external constructors.

@ethers would you be interested in documenting the above in the main docs? This question comes up a few times, good have it explained.

@axic I can pick this up if @ethers hasn't yet?

@elenadimitrova yes, please take it, it would be great having this document. @ethers has not expressed interest, it is safe to assume he hasn't started working on it.

Is this the best place in the documentation for that @axic
http://solidity.readthedocs.io/en/develop/contracts.html#abstract-contracts

Shall we roll in #627 here as well?

@elenadimitrova I think it would make sense introducing a new section for constructors somewhere in the Inheritance section.

@elenadimitrova Thanks for documenting the reason for internal constructors.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chriseth picture chriseth  路  3Comments

AnthonyAkentiev picture AnthonyAkentiev  路  3Comments

chriseth picture chriseth  路  4Comments

chriseth picture chriseth  路  4Comments

Dohtar1337 picture Dohtar1337  路  4Comments