Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

constructor, internal, and why not external? #3132

Closed
ethers opened this issue Oct 26, 2017 · 9 comments
Closed

constructor, internal, and why not external? #3132

ethers opened this issue Oct 26, 2017 · 9 comments

Comments

@ethers
Copy link
Member

ethers commented Oct 26, 2017

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?

@axic
Copy link
Member

axic commented Oct 26, 2017

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

@ethers
Copy link
Member Author

ethers commented Oct 26, 2017

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.)

@chriseth
Copy link
Contributor

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

@axic
Copy link
Member

axic commented Oct 27, 2017

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

@elenadimitrova
Copy link
Collaborator

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

@axic
Copy link
Member

axic commented Dec 13, 2017

@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.

@elenadimitrova
Copy link
Collaborator

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?

@axic
Copy link
Member

axic commented Dec 22, 2017

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

@ethers
Copy link
Member Author

ethers commented Jul 1, 2018

@elenadimitrova Thanks for documenting the reason for internal constructors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants