I want a data structure (say X) resembling a singly linked list, with a catch, that its nodes can be of of either of two types, just a value (atom) , or a X itself.
Is the following a right way to approach it ?
Code:class s_expr; class atom; class slist; s_expr* s_factory(const std::string& s); class s_expr { enum Type{atom,list} type; protected: std::string symbol; public: virtual s_expr eval(const s_expr& s); }; class atom:public s_expr { public: s_expr eval(const s_expr& s){/*Returns a value grabbed from a lookup table*/}; }; class slist : public s_expr { //Singly linked list implementation, with s_expr `s as nodes. };



LinkBack URL
About LinkBacks



