C++ map, template and container class problem

Questions about programming languages and debugging
Post Reply
User avatar
Lundis
Distorter of Reality
Distorter of Reality
Posts: 543
Joined: 22 Aug 2008, 16:00
15
Location: Deadlock of Awesome
Contact:

C++ map, template and container class problem

Post by Lundis »

I'm currently writing a very simple LISP interpreter to learn c++ and I've learned a lot so far but now I'm stuck. I want a map to hold variables of all kinds(numbers, strings, lists etc). That sounded simple at first but it turned out to be a problem...

After trying to understand what the error messages meant I figured out that I had to make a container class, so I did and here's the relevant code:

Code: Select all

...
#include <string>
#include <map>

class varholder {
	template <class T>
	T* varpnt; //error
};
std::map<std::string, varholder> variablemap;

...
int main() ...
Now I get this error:
lispmain.cpp:8: error: data member ‘varpnt’ cannot be a member template

Any ideas on how I should do this? Is there a nice way to get this working or do I have to make an ugly container class that contains pointers to all the datatypes I want, with only one actually being used?

Post Reply