问题描述
// SPDX-License-Identifier: MIT
pragma solidity ^0.5.16;
// creating the contract
contract rating {
// creating structure to model the product
struct Product {
uint id;
string name;
uint ratingCount;
}
// use mapping to get or fetch the contestant details
mapping(uint => product) public products;
// add a public state variable to keep track of product count
uint public productsCount;
constructor () public {
addProduct("Nike");
addProduct("Adidas");
}
// add a function to add product
// for private variable we use underscore in the start of variable _name
function addProduct(string memory _name) private {
productsCount++;
products[productsCount] = Product(productsCount,_name,0);
}
}
解决方法
Solidity 区分大小写。
您已经定义了一个名为 Product
(大写 P)的结构,但您的映射使用的是 product
(小写 p)。
解决方案:使用正确的形式Product
mapping(uint => Product) public products;
,
抱歉,我发现问题出在映射中
mapping(uint => product) public products;
我错误地使用了小 p 而不是大写 P。这在迁移我的智能合约时给了我一个错误,因为我的结构名称以大写 P(产品)开头。 所以不是小 p 只是将 p 更改为 P。
mapping(uint => Product) public products;