unresolved overloaded function type
I get this error with the following code, but i am not sure what it means? It essentially is the same as my pop method, but not erasing the key/value.
1 2 3
|
test3.cpp: In function 'int main()':
test3.cpp:60:29: error: invalid types '<unresolved overloaded function type>[const char [4]]' for array subscript
std::cout << d.get["key"] << std::endl;
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <sstream>
#include <iomanip>
template <class KEY, class VALUE>
class Dict{
public:
std::map<KEY, VALUE> dictionary;
void update(KEY k, VALUE v){
dictionary[k] = v;
}
std::vector<KEY> keys(){
std::vector<KEY> v;
for(class std::map<KEY, VALUE>::const_iterator it = dictionary.begin();
it != dictionary.end(); ++it){
v.push_back(it->first);
}
return v;
}
std::vector<VALUE> values(){
std::vector<VALUE> v;
for(class std::map<KEY, VALUE>::const_iterator it = dictionary.begin();
it != dictionary.end(); ++it){
v.push_back(it->second);
}
return v;
}
VALUE pop(KEY k){
VALUE val = dictionary[k];
dictionary.erase(k);
return val;
}
VALUE get(KEY k){
VALUE val = dictionary[k];
return val;
}
};
int main(){
Dict<std::string, std::string> d;
d.update("key", "value");
d.update("key2", "value2");
for (auto i:d.keys())
std::cout << i << std::endl;
for (auto i:d.values())
std::cout << i << std::endl;
std::cout << "removing " << d.pop("key2") << '\n';
std::cout << d.dictionary["key"] << std::endl;
std::cout << d.get["key"] << std::endl;
}
|
Last edited on
Oh i am an idiot, typod the parenthesis
d.get("key")
Last edited on
Topic archived. No new replies allowed.