I have some codes like these:

process(void*p1,long lNum1,long Type1,void p2,long lNum2,long lType2,Param * toher...)
{
  switch(lType1)
   case TIA_8U:
      switch(lType2)
        case TIA_16U:
          CMatrix<BYTE>* pIn = (CMatrix<BYTE>*) p1;
          CMatrix<USHORT>* pOut = (CMatrix<USHORT>*)p2;
          Run<CMatrix<BYTE>, CMatrix<USHORT>,BYTE,USHORT>(pIn,lNum1,pOut,lNum2,otherparams....)
          break;
          ...
}

Now I have a problem: the number of data types is at least 4,so there are at least 16 combinations.When the data type number increases or it has more inputs such as pIn1,pIn2...then there'll be more and more combinations,gold help me!I thought i can make some macros to resolve this,but I failed.Can macro help me? Thank you for any help.
Gary CHine

Think: a preprocessor expands macros not only before the program run but before a compiler process sources! I can't just imagine what kind of useful macros you hope to invent...
As usually, the best MxN code burst medicine is polymorhism. But now I can't suggest any solution on the too brief problem explanation with obviously wrong code (void p2, undefined Param types etc) illustration...

Thank you for your help! I feel ashamed of this wrong code ,'void p2 ' should be 'void*p2',p1 and p2 are pointers to satellite image blocks with different data types such as byte ,unsigned short or float and so on.I want to make no consideration about different data types,so I come to use the tamplate function names 'Run'.
CMatrix<T> overrides operator() to return a refference of pixel value on the postion of (i,j),Now I can write pOut(i,j) = SomeMethod(pIn(i,j)).Polymorhism is commited ,so we can create byteMatrix ,UShortMatrix Float Matrix ...they inherite the base class CMatrix?Additional to illustrate is that Param * toher is a pointer to paragrams list,each algorithem has various paragrams, but it has little relationship with the topic here.Thank you again and forgive my poor English.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.