Ok, so I'm writing a simple scheme interpreter (ala Bootstrap Scheme), but in C++11 (this question is not specific to C++11 however). I'm trying to come up with a reasonable form for my class "Object" to take. Currently, my layout is something like:
typedef union {
int i;
double d;
char c;
} value;
class Object {
public:
//Constructors and stuffs...
private:
obj_type type;
value val;
list<Object> l;
};
I tried putting the list in the union (which was in the class), but the compiler complained. My question is this: is it possible to put a list of a class in the class itself? I would think I should be able to, since by default the list will have no Objects in it (so no infinite growth).
Secondly, if this isn't possible, are there any other suggestions for how to implement this? I know I can implement the list C-style (with pointers) but STL lists make things so much simpler.
UPDATE: Ok, so pointers seem like a nice solution. I don't want to use Boost because that's a library I haven't used extensively yet and I'm doing this partly as an exercise to gain greater mastery over the STL.
UPDATE 2: New code looks like this:
class Object {
//...
private:
obj_type type;
int i;
double d;
char c;
deque<Object*> l;
};
But I'm still getting the compiler error: ‘deque’ does not name a type
.