I'm very new to C++. I just started to pick it up this last week or so.
I am trying to write a macro to be able to access and add items to a std::map. However, I'm not finding this to work. What am I doing wrong or is there a better way to implement this?
#include <iostream>
#include <string>
#include <map>
typedef struct {
std::string name;
int value;
} Token;
std::map<std::string, Token> ALL_TOKENS;
#define T(macro, name, value) \
Token macro {name, value}; \
ADD(name, macro); \
T(TEST, "Test", 1); \
#define ADD(str, tok) \
ALL_TOKENS.insert(std::pair<std::string, Token>(str, tok)); \
#define GET(str) \
ALL_TOKENS[str]; \
int main(int argc, const char * argv[]) {
Token tok = GET("Test");
printf("%s", tok.name.c_str());
return 0;
}