0

First, I apologize as this question has been asked before; however, the solutions didn't seem to work in the context of my contract. When I remove "var", Remix does not recognize "car", but with it, I get the warning that "var" is deprecated. I've tried using "struct car" and "struCar", but neither worked. How should I replace var?

mapping(uint => Vehicle) vehicles;


function newCar(bytes32 _color, bytes32 _make, uint32 _year) public returns (uint ID) {
    var car = vehicles[carID];
    car.color = _color;
    car.make = _make;
    car.year = _year;
    carID ++;
    ID = carID;
1

Just replace var with the actual type:

Vehicle car = ...;
4
  • Hmm. With that I get "Warning: Variable is declared as a storage pointer. Use an explicit "storage" keyword to silence this warning". So can I enter "Vehicle storage car =" ? Also, is there anything bad about pointing to storage? – CreatedAMadman May 27 '18 at 21:56
  • 1
    To silence the warning, use Vehicle storage car = .... – user19510 May 27 '18 at 21:57
  • Okay, thank you. But just curious. Why does it warn me that it points to storage? Is this because storage is expensive and it wants to make sure I intended it for storage? – CreatedAMadman May 27 '18 at 21:59
  • 1
    It's just to prevent mistakes. uint256 x is in memory, while Vehicle y is in storage. Storage is the rare case, and being explicit tells the compiler you know what's happening. – user19510 May 27 '18 at 22:03

Your Answer

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

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