1

I'm trying to run my code but i get this error: Could not compile source code.

" Identifier already declared. function addCar(string _make, string _model, unit _pricePerDay, uint _minRentalDay, uint _maxRentalDay) public onlyOwner{ ^ Spanning multiple lines."

i don't understand because there shouldn't be a problem, Here's my function:

function addCar(string _make, string _model, unit _pricePerDay, uint _minRentalDay, uint _maxRentalDay) public onlyOwner{

make = _make;
model = _model;
pricePerDay = _pricePerDay;
minRentalDay = _minRentalDay;
maxRentalDay = _maxRentalDay;

Car newCar = cars[numofCars];
nameToKeys[name].keys.push(numofCar); //add the key to the name's keys

newCar.VechileOwner = msg.sender;
newCar.make = make;
newCar.model = model;
newCar.available = false;
newCar.pricePerDay = pricePerDay;
newCar.minRentalDay = minRentalDay;
newCar.maxRentalDay = maxRentalDay;

NewCar(numofCars,msg.sender);
ids.push(numofCars);
numofCars++;
}

Much appreciated.

  • I'm guessing the already-declared identifier is addCar. Is addCar declared somewhere else in your contract? (Maybe the name of a variable? Or another function?) – smarx Jan 21 '18 at 19:40
  • Post the complete contract. You have a duplicate declaration somewhere. – Adam Kipnis Jan 21 '18 at 19:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.