Solidity
預期標識符,但獲得保留關鍵字“參考”產品公共參考;^——–^
大家好,我是初學者。我想做一個創建契約的功能。
我在網際網路上找到了一個範例,但給了我一個錯誤,所以我不知道該怎麼辦。
任何人都可以幫助我嗎?
pragma solidity ^0.5.0; contract Product { Factory public factory; Product public reference;//**here's the error** function Product(Product _reference, Factory _factory){ reference = _reference; factory = _factory; } function haveFactoryCreateProductWithReferenceToThis() public { emit ProductCreated(factory.createNewProduct(this)); } event ProductCreated(Product indexed product); } contract Factory{ function createNewProduct(Product _reference) public returns (Product) { Product p = new Product(_reference, this); return p; } }
pragma solidity ^0.5.0; contract Product { Factory public factory; Product public x; constructor(Product _reference, Factory _factory) public{ x = _reference; factory = _factory; } function haveFactoryCreateProductWithReferenceToThis() public { emit ProductCreated(factory.createNewProduct(this)); } event ProductCreated(Product indexed product); } contract Factory{ function createNewProduct(Product _reference) public returns (Product) { Product p = new Product(_reference, this); return p; } }
嘿,我做了一個小改動,現在可以使用了!