Quote Originally Posted by jwspring View Post
I tried to use template but I don't know how to convert a template variable to char*. any idea?
Code:
#include <string>

template <class T>
T PerformOperation (T V1 , const std::string& Operator, T V2 ) 
{
     T result = T();
      if (Operator == "&&")
         result = V1 && V2;
      else
      if  (Operator == "||")
         result = V1 || V2 ;
     //...
      return result;   
}
Note the usage of std::string, not char*. Second, note that result is assigned a default value at the beginning.

Even the approach above can be improved on, especially since all you're doing is a binary operation between two operands. This can be classed or grouped in a way where you're not writing endless if() statements.

Regards,

Paul McKenzie