Data location must be “memory” or “calldata” for parameter in function, but none was given

dapp-developmentdappsgo-ethereumsolidity

First just have a look at my easy code so that I can explain by giving references.

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;

contract GeoSpatialData{
    
    struct GeoData{
        uint id;
        address owner_address;
        string data_name;
        string data_year;
        string data_description;
        string data_img_url;
        string data_url;
        string data_category;
        string data_published_date;
    }
    GeoData[] public geoData;
    // write function
    function createData(string memory _data_name,address _owner_address,string _data_year,string _data_description,string _data_image_url,string _data_url,string _data_published_date ) public{
           
    }

    // read all data  function
    function readData() public{

    }

    // read single data function 
    function readSingle() public{

    }    
}

Now I have a struct of GeoData as you can see. What I want is to create an object of this so definitely I am going to need the parameters while passing them in the create data. I am getting the error that Data location must be "memory" or "calldata" for parameter in function, but none was given.

I learned the way to create objects from this course. Here is the link of the github whose code inspired me to write code like this.

I also have one more question: Is storing all the data in an array a good idea? Can't I store as class objects? Does solidity support these programming concepts?

Best Answer

You have to set data location type to function parameters & returns to establish where the data would be during the life time of the function you would be calling. "memory" & "calldata" & "storage", would establish where the function parameter data would be store and where the data is placed so the function return can return these data.

Watch these videos and example code to understand better :>