2014-02-21 57 views
0

我试图创建一个使用unordered_map哈希表,但在Visual Studio 2010中没有实例得到了错误模板函数与unordered_map

IntelliSense: no instance of function template "std::tr1::unordered_map<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>::emplace [with _Kty=std::string, _Ty=std::string, _Hasher=std::hash<std::string>, _Keyeq=std::equal_to<std::string>, _Alloc=std::allocator<std::pair<const std::string, std::string>>]" matches the argument list 

以下代码段。上述错误出现在我使用emplace call的时候。如何解决这个错误?

#include<iostream> 
#include<unordered_map> 
#include<string> 

int main() 
{ 
    std::tr1::unordered_map <std::string, std::string> hashtable; 
    std::tr1::unordered_map <int,int> intmap; 
    intmap.emplace(10,20); 
    hashtable.emplace("www.element14.com","184.51.49.225"); 
    std::cout << "IP Address : " <<hashtable["www.element14.com"] <<std::endl; 
    return 0; 
} 
+0

上述工作正常,如果我使用插入像'hashtable.insert(std :: make_pair(“www.newark.com”,“184.51.50.121”));' –

回答

1

Visual C++ 2010(和事实上的2012)不支持可变参数模板,这是如何实现“emplace”的。在2012年,他们使用了一堆令人讨厌的宏来解决这个问题,但是在2010年,emplace仅实现了一个参数(因此与插入非常相当)。