aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbitshift <bitshift@posteo.org>2018-03-02 23:44:35 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2018-04-04 00:21:55 +0800
commit07c74ef9241b1fe4fdec5cf4bd97e2c1aedb8d0d (patch)
treedf68680d398b89c088da57b297eb1b9eeb389193
parentd664a599e68291166c47fcece464cb8d0af31df8 (diff)
downloaddexon-solidity-07c74ef9241b1fe4fdec5cf4bd97e2c1aedb8d0d.tar
dexon-solidity-07c74ef9241b1fe4fdec5cf4bd97e2c1aedb8d0d.tar.gz
dexon-solidity-07c74ef9241b1fe4fdec5cf4bd97e2c1aedb8d0d.tar.bz2
dexon-solidity-07c74ef9241b1fe4fdec5cf4bd97e2c1aedb8d0d.tar.lz
dexon-solidity-07c74ef9241b1fe4fdec5cf4bd97e2c1aedb8d0d.tar.xz
dexon-solidity-07c74ef9241b1fe4fdec5cf4bd97e2c1aedb8d0d.tar.zst
dexon-solidity-07c74ef9241b1fe4fdec5cf4bd97e2c1aedb8d0d.zip
Updates docs to new constructor syntax.
-rw-r--r--docs/contracts.rst32
1 files changed, 26 insertions, 6 deletions
diff --git a/docs/contracts.rst b/docs/contracts.rst
index 8cc4f6b2..c4eda8dc 100644
--- a/docs/contracts.rst
+++ b/docs/contracts.rst
@@ -40,7 +40,7 @@ This means that cyclic creation dependencies are impossible.
::
- pragma solidity ^0.4.16;
+ pragma solidity ^0.4.20; // should actually be 0.4.21
contract OwnedToken {
// TokenCreator is a contract type that is defined below.
@@ -52,7 +52,7 @@ This means that cyclic creation dependencies are impossible.
// This is the constructor which registers the
// creator and the assigned name.
- function OwnedToken(bytes32 _name) public {
+ constructor(bytes32 _name) public {
// State variables are accessed via their name
// and not via e.g. this.owner. This also applies
// to functions and especially in the constructors,
@@ -976,11 +976,32 @@ virtual method lookup.
Constructors
============
-A constructor is an optional function with the same name as the contract which is executed upon contract creation.
+A constructor is an optional function declared with the ``constructor`` keyword which is executed upon contract creation.
Constructor functions can be either ``public`` or ``internal``.
::
+ pragma solidity ^0.4.20; // should actually be 0.4.21
+
+ contract A {
+ uint public a;
+
+ constructor(uint _a) internal {
+ a = _a;
+ }
+ }
+
+ contract B is A(1) {
+ constructor() public {}
+ }
+
+A constructor set as ``internal`` causes the contract to be marked as :ref:`abstract <abstract-contract>`.
+
+.. note ::
+ Prior to version 0.4.21, constructors were defined as functions with the same name as the contract. This syntax is now deprecated.
+
+::
+
pragma solidity ^0.4.11;
contract A {
@@ -995,7 +1016,6 @@ Constructor functions can be either ``public`` or ``internal``.
function B() public {}
}
-A constructor set as ``internal`` causes the contract to be marked as :ref:`abstract <abstract-contract>`.
.. index:: ! base;constructor
@@ -1009,11 +1029,11 @@ the base constructors. This can be done in two ways::
contract Base {
uint x;
- function Base(uint _x) public { x = _x; }
+ constructor(uint _x) public { x = _x; }
}
contract Derived is Base(7) {
- function Derived(uint _y) Base(_y * _y) public {
+ constructor(uint _y) Base(_y * _y) public {
}
}