0
contract InsanFactory{

  struct Accenture{
    uint id;
    string name;
    uint salary;
  }


  mapping (address=>Accenture) public accemployee;

  constructor(uint _id,string  name,uint _salary){
    accemployee[msg.sender] = setter(uint _id,string name,uint _salary);
    accemployee[msg.sender] = Accenture(uint _id,string name,uint _salary);

  }

  Accenture[] public acc;

  function setter(uint _id,string memory _name,uint _salary) public {
   
    Accenture memory a  = Accenture(_id,_name,_salary);
    acc.push(a);
    acc[0].id = 2;
  }

Getting the below error inside the constructor :

=>ParserError: Expected ',' but got identifier
  --> dummy.sol:17:42:
   |
17 | accemployee[msg.sender] = Accenture(uint _id,string name,uint _salary);
  1. Whats wrong I'm doing inside the constructor causing the above error?

1 Answer 1

1

Looks like in these lines you need to remove the type specification:

accemployee[msg.sender] = setter(uint _id,string name,uint _salary); 
accemployee[msg.sender] = Accenture(uint _id,string name,uint _salary);

So turn the above statements into:

accemployee[msg.sender] = setter(_id, name, _salary);
accemployee[msg.sender] = Accenture(_id, name, _salary);

Notice how we just send in the values directly, we don't specify the type as we send them in.

But besides this there are a few other issues in your code. Without including the SPDX license statement and noting that this is for Solidity ^0.8.0, this code should work:

contract InsanFactory{

    struct Accenture{ uint id; string name; uint salary; }
    mapping (address=>Accenture) public accemployee;

    Accenture[] public ACC;

    constructor(uint _id,string memory name,uint _salary){ 
        setter(_id, name, _salary);
        accemployee[msg.sender] = Accenture(_id, name, _salary);
    }

    function setter(uint _id,string memory _name,uint _salary) public {
        Accenture memory a  = Accenture(_id,_name,_salary);
        acc.push(a);
        acc[0].id = 2;
    }
}

There are probably some things I would code differently, but just trying to get it working as close to what you shared here.

1
  • Thank you so much for the quick response!Also I'm trying to enter in the programming world as new amateur.Also do you mind sharing how would you do this in different way?
    – newlearner
    Commented Jul 16, 2022 at 19:53

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.