11922911

|
分享:
▲
更新 版本 1.1.0 (2024-3-15) :加入多重繼承功能 (詳見 oo_multiple_inheritance.sma), 多重繼承是仿照類似 python 的 MRO order 修正 oo_get 和 oo_set 不能使用類別名稱搜索 ex: oo_get(@this, "Class@var") 多重繼承範例:#include <amxmodx> #include <oo>
public oo_init() { oo_class("B1"); { oo_var("B1", "a", 1); oo_ctor("B1", "Ctor", @cell); oo_mthd("B1", "Print"); oo_mthd("B1", "Method1"); }
oo_class("B2"); { oo_var("B2", "b", 1); oo_ctor("B2", "Ctor", @cell); oo_mthd("B2", "Print"); oo_mthd("B2", "Method2"); }
oo_class("D", "B1", "B2"); { oo_var("D", "hp", 1); oo_ctor("D", "Ctor", @cell, @cell, @cell); oo_mthd("D", "Print"); } }
public plugin_init() { new obj = oo_new("D", 100, 689, 777); oo_call(obj, "Print"); }
public B1@Ctor(a) { oo_set(oo_this(), "a", a); }
public B2@Ctor(b) { oo_set(oo_this(), "b", b); }
public D@Ctor(hp, a, b) { oo_super_ctor("B1", a); oo_super_ctor("B2", b); oo_set(@this, "hp", hp); }
public D@Print() { oo_call(@this, "Method1"); oo_call(@this, "Method2");
oo_call(@this, "B1@Print"); oo_call(@this, "B2@Print"); server_print("D@Print(hp=%d, a=%d, b=%d)", oo_get(@this, "hp"), oo_get(@this, "a"), oo_get(@this, "b")); }
public B1@Method1() { server_print("B1@Method1()"); } public B2@Method2() { server_print("B2@Method2()"); }
public B1@Print() { server_print("B1@Print()"); } public B2@Print() { server_print("B2@Print()"); }
輸出結果 B1@Method1() B2@Method2() B1@Print() B2@Print() D@Print(hp=100, a=689, b=777)
[ 此文章被11922911在2024-03-17 10:29重新編輯 ]
|
|
x1
[5 樓]
From:香港沒有資料 | Posted:2024-03-15 20:37 |
|
|
|