
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
//在初始化的时候,多线继承理解
contract A {
string text;
constructor(string memory aa) {
text\=aa;
}
function a() external {
text \="a";
}
}
contract B {
string textb;
constructor(string memory bb) {
textb\=bb;
}
}
//第一种,已知传入参数
contract C is A("S"),B("SS"){
}
//第二中,未知
contract D is A,B {
constructor(string memory aa,string memory bb) A(aa) B(bb) {
}
}
//第三种,混用
contract E is A("ss"),B {
constructor(string memory BB) B(BB) {
}
}
//进阶一下,继承的父级函数调用
contract AAA1 {
event aaaa(string textt);
function aaa() virtual public {
emit aaaa("i am aaa");
}
}
contract BBB is AAA1{
function aaa() virtual override public {
emit aaaa("i am BBB");
}
}
contract CCC is BBB{
function ccc() public {
//手动寻找指定父级的函数
BBB.aaa(); //调用对方,那么对方的函数必须是public
}
}
contract DDD is CCC{
function fun() public {
//自动寻找父级函数的方法
super.aaa(); //调用对方,那么对方的函数必须是public
}
}
//动态常量测试
contract dff {
address immutable user;
constructor(address _user) {
user \= _user;
}
}
contract df2f {
address immutable user \= msg.sender;
function xiugai(address newuser) public {
//user = newuser; //这里的user是不可修改的 因为上面使用了 immutable定义了是常量,只能在初始化中赋值
}
}
//支付的初体验
contract paytest {
// 给这个合约地址打上关键词pay,这个合约地址也就可以支付给其他账号了
address immutable admin;
constructor() {
admin \= msg.sender;
}
// 带上 payable 就可以支付主币了
function pay() payable public {
}
//查询当前合约余额
function select() public view returns (uint) {
return address(this).balance;
}
//查看合约地址
function getContractAddress() external view returns (address){
return address(this);
}
}