宅D嘉
有著十年以上的軟體開發經驗,喜歡投資理財,目前喜歡研究區塊鏈相關,了解虛擬貨幣投資或者是區塊鏈開發,喜歡把複雜的東西簡單化,樂於分享我的理財投資生活。
// SPDX-License-Identifier: MITpragma solidity ^0.8.13;//汽車模版contract Car {string public model;address public owner;uint public cost;constructor(string memory _model, address _owner) payable {model = _model;owner = _owner;cost = msg.value;}}//汽車工廠contract CarFactory {Car[] public cars;// 記錄汽車// function create(string memory _model) public {// Car car = new Car(_model, address(this));// cars.push(car);// }function createWithMoney(string memory _model) public payable {//必須有足夠的乙太幣才行require(msg.value >=1 ether, "Not enough money");//創建一台車Car car = new Car{value: msg.value}(_model, address(this));cars.push(car);//記錄所有創建的車}}