I want to use the class more intelligently to avoid checking series
datatypes in running time.
for example, in the original codes:
switch(type_flag) {
case INT_TYPE:
break;
case FLOAT_TYPE:
break;
... ...
}
This is a textbook application of polymorphism.
Define an abstract base class, let's say MatBase, which contains a Mat (or a
pointer to one). For eachdatatype, define a derived class: IntMat, FloatMat,
etc. Finally, define a factory function CreateMat, which takes a Mat as
argument and spits out the appropriate derived class wrapper.
The factory function will still have to contain a switch on type_flag, but
thereafter alltype-dependent processing can be done in virtual functions
declared but not defined in BaseMat and implemented for eachdatatypein the
corresponding derived class, so that no switching is required.
Actually, I would call this a textbook anti-application of polymorphism.