I wanted to do a get() to return some contract information, including an array, but when I put it gives this error:
browser/leilaoSimples.sol:34:9: TypeError: Data location must be "memory" for return parameter in function, but none was given. uint[] _historicoDeOfertas ^------------------------^
function get() public view returns(
address _dono,
uint _contadorDeOfertas,
address _comprador,
uint _ultimaOferta,
uint[] _historicoDeOfertas
){
return(
dono,
contadorDeOfertas,
comprador,
valorAtual,
ofertas
);
}
Full code (Note: it's in Portuguese)
pragma solidity >=0.5.1 <0.6.0;
contract leilaoSimples{
uint valorAtual;
address payable comprador;
address dono;
string nome;
uint contadorDeOfertas = 0;
uint[] ofertas;
constructor(uint valorInicial) public{
valorAtual=valorInicial;
dono = msg.sender;
}
function set() public payable{
uint oferta = msg.value;
require(oferta>valorAtual, "Oferta abaixo do valor atual.");
require(comprador!=msg.sender, "Você deu o último lance.");
comprador.transfer(valorAtual);
valorAtual = oferta;
contadorDeOfertas++;
ofertas.push(valorAtual);
comprador = msg.sender;
}
function get() public view returns(
address _dono,
uint _contadorDeOfertas,
address _comprador,
uint _ultimaOferta,
uint[] _historicoDeOfertas
){
return(
dono,
contadorDeOfertas,
comprador,
valorAtual,
ofertas
);
}
}
memoryis required there but I didn't understand it - why couldn't it return a storage pointer? I hope someone else can post a better answer which explains this. – Lauri Peltonen Sep 18 '19 at 18:10