0
// SPDX-License_identifier: MIT
pragma solidity >=0.7.0;

import "./struct.sol";

contract storageFactory{

  function createSimpleStorageContract()  public{
    struct simpleStorage = new struct();
  }
}

the code for struct.sol is:

// SPDX-License-identifier: MIT
pragma solidity >=0.7.0;

contract storageb{
  struct people{
    uint256 favN;
    string name;
  }

  people[] public array;
  mapping(string => uint256) public nameToFavNumber;

  function addPerson( string memory _name,uint _favN) public{
    array.push(people(_favN, _name));
    nameToFavNumber[_name]=_favN;
  }

}

Compiler error:

from solidity:
    ParserError: Expected primary expression.
    --> learn/storagrFactory.sol:9:9:
      |
    9 |         struct simpleStorage = new struct();
      |         ^^^^^^
1
  • 1
    Please can you specify what do you do in your code? Do you want to instantiate a struct? Commented Mar 13, 2022 at 11:47

2 Answers 2

1

The contract name in struct.sol is storageb and not struct (which is a solidity keyword).

Calling import "struct.sol"; is quite similar to copy&paste content of struct.sol in your storagrFactory.sol

You need to use storageb instead of struct in storagrFactory.sol to make your contract compile.

1

Try to change your function to this:

function createSimpleStorageContract()  public {
    storageb simpleStorage = new storageb();
  }

Hope it helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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