Verwendung für Solidität
// `for` is used to attach functions to variable types.
// Example:
function sum(uint a, uint b) returns(uint) {
return a + b;
}
using sum for uint;
// then you can use this inside your contracts:
contract MyContract {
function add1(uint num) public pure returns(uint) {
return num.sum(1);
// `num` is passed as the first parameter (`a`) and `1` as the second (`b`)
}
}
// You can also use libraries this way:
library Math {
function sum(uint a, uint b) returns(uint) {
return a + b;
}
function sub1(uint x) returns(uint) {
return(x - 1);
}
}
contract MyContract {
using Math for uint;
function uselessCalculation(uint x, uint y) returns(uint) {
return x.sum(y).sub1();
}
}
Sheeeev66