From c008403262c8a559156d613cc288a10d4d9b4a5a Mon Sep 17 00:00:00 2001 From: elenadimitrova Date: Sun, 31 Dec 2017 16:29:45 +0200 Subject: [PATCH] Add section on Constructors in documentation --- docs/contracts.rst | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/docs/contracts.rst b/docs/contracts.rst index fcc26b247397..273a9923c849 100644 --- a/docs/contracts.rst +++ b/docs/contracts.rst @@ -953,6 +953,29 @@ not known in the context of the class where it is used, although its type is known. This is similar for ordinary virtual method lookup. +.. index:: ! constructor + +Constructors +============ +Constructor is an optional function with the same name as the contract which is executed upon contract creation. +Constructor functions can be either ``public`` or ``internal``. + +:: + + contract A { + uint public a; + + function A(uint _a) internal { + a = _a; + } + } + + contract B is A(1) { + function B() public {} + } + +A constructor set as ``internal`` causes the contract to be marked as :ref:`abstract `. Child contracts of an abstract contract can call the super constructor. + .. index:: ! base;constructor Arguments for Base Constructors @@ -1025,6 +1048,8 @@ As an exception, a state variable getter can override a public function. .. index:: ! contract;abstract, ! abstract contract +.. _abstract-contract: + ****************** Abstract Contracts ******************