The function of dynamic Factory is slightly enhanced, supporting Create with parameters!

zhaozj2021-02-12  211

Here is specific usage, the Factory code needs to be adjusted, and later given. More unfortunately, the macro is not overloaded. It is to say that the registration has the parameters and the macro without parameters. I don't know if I can improve. When the dynamic crete is identified, then the parameters, for the incorrect Will return NULL! Class TT {public: tt () {a = 4;} int a;}; registerclass (12, tt) class P: public tt {public: p () {a = 2;} P (int b) {a = B;} P (int B, tt * c) {a = b * c-> a;}}; registerclass (13, p) regiSternarg1 (13, p, int) regissarg2 (13, p, int, tt *) Void main () {tt * t = (tt *) zfactory :: getInstance () -> CreateClass (12); tt * p = (tt *) zfactory :: getInstance () -> CreateClass (13); cout <

a

Cout <

a

P = (tt *) zfactory :: getInstance () -> CREATECLASS (13, 22); COUT <

a

P = (tt *) zfactory :: getInstance () -> CREATECLASS (13, 22, t); COUT <

a

}

转载请注明原文地址:https://www.9cbs.com/read-7723.html

New Post(0)