mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Clean up contracts.rst
This commit is contained in:
parent
f55fb808e9
commit
f125b2813e
@ -195,45 +195,47 @@ return parameter list for functions.
|
|||||||
uint public data;
|
uint public data;
|
||||||
}
|
}
|
||||||
|
|
||||||
An other contract ``D`` can call ``c.getData()`` to retrieve the value of data in state
|
In the following example, ``D``, can call ``c.getData()`` to retrieve the value of
|
||||||
storage and is not able to call ``f``. Contract ``E`` is derived from ``C`` and can call
|
``data`` in state storage, but is not able to call ``f``. Contract ``E`` is derived from
|
||||||
``compute``.
|
``C`` and, thus, can call ``compute``.
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
contract C {
|
contract C {
|
||||||
|
uint private data;
|
||||||
|
|
||||||
function f(uint a) private returns(uint b) { return a + 1; }
|
function f(uint a) private returns(uint b) { return a + 1; }
|
||||||
function setData(uint a) { data = a; }
|
function setData(uint a) { data = a; }
|
||||||
function getData() public returns(uint) {return data;}
|
function getData() public returns(uint) { return data; }
|
||||||
function compute(uint a, uint b) internal returns (uint) { return a+b;}
|
function compute(uint a, uint b) internal returns (uint) { return a+b; }
|
||||||
uint private data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract D {
|
contract D {
|
||||||
function readData() {
|
function readData() {
|
||||||
C c = new C();
|
C c = new C();
|
||||||
local = c.f(7); // error: member "f" is not visible
|
uint local = c.f(7); // error: member "f" is not visible
|
||||||
c.setData(3);
|
c.setData(3);
|
||||||
uint local = c.getData();
|
local = c.getData();
|
||||||
local = c.compute(3,5); // error: member "compute" is not visible
|
local = c.compute(3, 5); // error: member "compute" is not visible
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract E is C {
|
contract E is C {
|
||||||
function g() {
|
function g() {
|
||||||
C c = new C();
|
C c = new C();
|
||||||
uint val = compute(3,5); // acces to internal member (from derivated to parent contract)
|
uint val = compute(3, 5); // acces to internal member (from derivated to parent contract)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
.. index:: ! accessor;function, ! function;accessor
|
.. index:: ! accessor;function, ! function;accessor
|
||||||
|
|
||||||
Accessor Functions
|
Accessor Functions
|
||||||
==================
|
==================
|
||||||
|
|
||||||
The compiler automatically creates accessor functions for
|
The compiler automatically creates accessor functions for
|
||||||
all public state variables. For the contract given below the compiler will
|
all public state variables. For the contract given below, the compiler will
|
||||||
generate a function called ``data`` that does not take any
|
generate a function called ``data`` that does not take any
|
||||||
arguments and returns a ``uint``, the value of the state
|
arguments and returns a ``uint``, the value of the state
|
||||||
variable ``data``. The initialization of state variables can
|
variable ``data``. The initialization of state variables can
|
||||||
@ -245,6 +247,7 @@ be done at declaration.
|
|||||||
uint public data = 42;
|
uint public data = 42;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract Caller {
|
contract Caller {
|
||||||
C c = new C();
|
C c = new C();
|
||||||
function f() {
|
function f() {
|
||||||
@ -254,8 +257,8 @@ be done at declaration.
|
|||||||
|
|
||||||
The accessor functions have external visibility. If the
|
The accessor functions have external visibility. If the
|
||||||
symbol is accessed internally (i.e. without ``this.``),
|
symbol is accessed internally (i.e. without ``this.``),
|
||||||
it is evaluated as state variable and if it is accessed externally
|
it is evaluated as a state variable and if it is accessed externally
|
||||||
(i.e. with ``this.``), it is evaluated as function.
|
(i.e. with ``this.``), it is evaluated as a function.
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user