0

Usually this error shows up when declaring functions and goes away by adding "memory" next to the argument, but this time I can't get it to resolve. I'm trying to instantiate a struct that takes in two parameters:

struct Obj {
    string where;
    uint what;
    }

function do() public { obj=Obj("here",1); }

the line with the new Obj triggers: TypeError: Data location must be "storage", "memory" or "calldata" for variable, but none was given.

I tried putting "memory" all over the place, after the first argument, after the second, after both, after the function, etc. Nothing seems to appease the compiler.


I'm using pragma solidity ^0.8.0;

Eight Rice
  • 125
  • 1
  • 7

1 Answers1

1

This function works :

function foo() public {
Obj memory obj=Obj("here",1);
}

Solidity is a statically typed language so you have to specify the type of each variable.

For the difference between storage, memory, and calldata, you can check these two links :

clement
  • 4,302
  • 2
  • 17
  • 35