I am writing a lexical analyzer in C++ and have to include a to_string()
method for my subclasses. This method won't be used by the lexical analyzer but we are told we have to include them for debugging purposes. The to_string
methods I have written keep generating errors and I am not sure why. Here is what I have:
string *AddopToken::to_string()
{
token_type_type tokenType = get_token_type();
addop_attr_type addopAttr = get_attribute();
return "[TOKEN TYPE: " + tokenType + ", ATTRIBUTE TYPE: " + addopAttr + "]";
}
This seems like it should work, but for some reason it does not.
Here is the typedef for addop_attr_type
in the AddopToken header.
typedef enum addop_attr { ADDOP_ADD = 400,
ADDOP_SUB = 401,
ADDOP_OR = 402,
ADDOP_NO_ATTR = 499 } addop_attr_type;
So even though the type of addopAttr
is addop_attr_type
, all that really is is an int constant. I figured C++ could convert an int to a string. Is there a way to convert these variables to a string so my to_string()
will work correctly?