0
pragma solidity ^0.5.0;
contract Election{
  //model a candidates
  struct candidate
  {
    uint id;
    string name;
    uint votecount;
  }
  //store candidates
  //fetch candidate

  mapping(uint => candidate) public candidates;

  //store candidate count

  uint public candidatescount;

  function () Election public {
    addcandidate("candidate1");
    addcandidate("candidate2");
  }
  function addcandidate (string _name) private
  {
    candidatecount ++;
    candidates[candidatescount] = candidate(candidatescount, _name, 0);
  }
}
0
0

As long as string is dynamically-sized type, modern version of Solidity compiler require location to be explicitly specified like this:

function addcandidate (string memory _name) private

or

function addcandidate (string storage _name) private

For your purpose memory looks more relevant.

In both cases, _name is passed by reference, but in the former case the reference is address in memory, while in the latter case the reference is address in storage.

Not the answer you're looking for? Browse other questions tagged or ask your own question.