The following code fails to compile with error: Type struct SomeStruct memory is not implicitly convertible to expected type struct SomeStruct storage pointer.
contract StructExample {
struct SomeStruct {
int someNumber;
string someString;
}
SomeStruct[] someStructs;
function addSomeStruct() {
SomeStruct storage someStruct = SomeStruct(123, "test");
someStructs.push(someStruct);
}
}
while the following code does compile
contract StructExample {
struct SomeStruct {
int someNumber;
string someString;
}
SomeStruct someStruct;
SomeStruct[] someStructs;
function addSomeStruct() {
someStruct = SomeStruct(123, "test");
someStructs.push(someStruct);
}
}
Is there a way of initialising a struct to a storage variable rather than a memory variable?
Or is the first method outlined above the correct way to do it and there's just a bug in the Solidity compiler? The second method that does work is not ideal as you have to scope the storage variables at the contract level rather than within a function.