Can't use template with std::map
I'm writing a small scripting language. I'm using a global std::map to store variables, which can be of any type. However, I can't do
Code:
template <class T> Code:
void * varTable; Thanks in advance, Alek |
You are a dangerous man :)
I got it to create an inherited class like this: Code:
#include <map> |
Thanks. That would work, but it isn't quite what I wanted. I'd have to create a varTable for every possible type of variable. But hey, that still isn't as clunky as what I had before. I'll go ahead and write the code that way, and change it later if I find a better one. Gives me that adrenaline rush. Thanks again.
|
The problem is that the compiler can't use Koenig Lookup to figure out the type you need since you have no argument; if the function took an argument of type 'T' (or something that uses it, like 'vector <T>'), then the compiler could find out what type you need. Since you have no argument, you need to be explicit with the type in the call:
Code:
makeTable <double> (); FYI: if you DO have an argument, but it can't be used to deduce ALL template parameters, such as Code:
template <class A, class B> void Function(const A&); Code:
char arg; ta0kira |
All times are GMT -5. The time now is 07:36 AM. |