|
-
May 30th, 2013, 10:19 AM
#3
Re: Convert VB function to C++ / C code
 Originally Posted by jwspring
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
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|