#if question

Started by
1 comment, last by etothex 18 years, 3 months ago
´hello Iam just wondering if its possible to compare strings instead of values with #if and if then it possible to put in a macro some psudo code: #define MACRO(string) #if string == "hello" (1273) #elif string == "yes" (6782) #else -1 #endif sadly this doesnt work=( Thanks for any help
Problems every where
Advertisement
No, that won't really work. For starters, I'm pretty sure that you can't have a #define trying to define another preprocessor directive. Also, it looks like "string" is a variable. The preprocessor stuff is handled before the code is compiled and linked. So, you can't rely on anything that could possibly changed at runtime in a preprocessor directive.
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper
No, and you probably shouldn't use a macro for this. A simple function will do:

int fn(const std::string &s) {   if(s == "hello") {      return 1273;   } else if (s == "yes") {      return 6782;   } else {      return -1;   }} 

This topic is closed to new replies.

Advertisement