C++:Creating a class for containing different types -
i new c++ actually, came python c++ reason. want create symbol_table compiler having 3 different methods.
let's consider type xxx
the code this:
class symbol_table { public: //store integer symbol table , return address of type xxx xxx add_int(int ); //store string symbol table , return address of type xxx xxx add_string(char ); xxx lookup(int x) { //if x exist in table return location } xxx lookup(char x) { //if x exist in table return location } }; what want returning address of type xxx same in both methods.
edit
so lookup this
symbol_table table ; xxx location1,location2; location1 = table.add_int(1); location2 = table.add_string("object"); table.lookup(1); //should return location1 table.lookup("object"); //should return location2
this can addressed packing data types stored c union structure. or can use fancy boost::variant.
typedef boost::variant<int, std::string> value_type_t; std::vector<value_type_t> symbol_table; value_type_t v1(100); symbol_table.push_back(v1); value_type_t v2("this string"); symbol_table.push_back(v2);
Comments
Post a Comment