引用类型是通过引用传递的数据类型,即指向存储实际数据的位置的指针。
# @version ^0.3.7
struct Person:
name: String[100]
age: uint256
# Fixed sized list
nums: public(uint256[10]) # must be bounded
myMap: public(HashMap[address, uint256])
person: public(Person)
@external
def __init__():
# This updates self.nums[0]
self.nums[0] = 123
self.nums[9] = 456
# Copies self.nums to array in memory.
# Does not modify referenced variable (self.nums)
arr: uint256[10] = self.nums
arr[0] = 123
# This updates self.myMap
self.myMap[msg.sender] = 1
self.myMap[msg.sender] = 11
# This updates self.person
self.person.age = 11
self.person.name = "Vyper"
# Person struct is copied into memory.
# Does not modify referenced variable (self.person)
p: Person = self.person
p.name = "Solidity"
```
---
## 关注我们
[Yanbo的Twitter](https://twitter.com/YanboOfficial)|[Web3Club的Twitter](https://twitter.com/Web3ClubCN)
加入Web3Club 官方讨论群:YanboTravelAllWorld(微信号)
[加入我们](https://github.com/Web3-Club/Intro./blob/main/Join%20club.md)