没有构造函数可以采用源类型
no constructor could take the source type
我一直收到错误,没有构造函数可以采用源类型,或者构造函数重载解析。
在代码的开头,我声明了一个无序映射。
unordered_map<char * , a_dictionary * > Mymap;
unsigned char hash[20];
char hex_str[41];
string answer, line;
int yes=0;
cout<<"Press 1 if you would like to use the default file(d8.txt) or press 2 if you want your own file"<<endl;
getline(cin,answer);
stringstream(answer)>> yes;
if(yes == 1 )
{
ifstream myfile("d8.txt");
if (myfile.is_open())
{
while ( myfile.good() )
{
getline (myfile,line);
//cout<<line<<endl;
a_dictionary * dic = new dictionary();
dic->word = line;
const char * c= line.c_str();
sha1::calc(c,line.length(), hash);
sha1::toHexString(hash,hex_str);
Mymap.insert(hex_str, dic); //
这里的行"mymap.insert"一直给我错误C2664:'sstd::_List_iterator<_Mylist>std::_Hash<_特征>::插入(std::_List_const_iterator<_Mylist>,_Valty(,即使我传递了正确的值,对吗?
这是调用HeXString 的函数
void toHexString(const unsigned char* hash, char* hexstring)
{
const char hexDigits[] = { "0123456789abcdef" };
for (int hashByte = 20; --hashByte >= 0;)
{
hexstring[hashByte << 1] = hexDigits[(hash[hashByte] >> 4) & 0xf];
hexstring[(hashByte << 1) + 1] = hexDigits[hash[hashByte] & 0xf];
}
hexstring[40] = 0;
}
您需要将其作为一对插入。
Mymap.insert(std::make_pair(hex_str, dic));
或者使用C++11初始化程序列表
Mymap.insert({hex_str, dic});
点击此处查看示例
或者,您可以使用operator[]
,生成更干净的代码
Mymap[hex_str] = dic;
http://cplusplus.com/reference/unordered_map/unordered_map/insert/检查插入声明。你想要std::对。
相关文章:
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 构造函数正在调用一个使用当前类类型的函数
- 如何修复函数样式强制转换或类型构造的预期"("?
- 具有默认模板类型的默认构造函数的类型推导
- C++LinkedList问题.数据类型之间存在冲突?没有匹配的构造函数
- 为什么类中的ostringstream类型的成员会导致";调用隐含删除复制构造函数";错误
- 在 c++ 中的模板实例化中使用带有构造函数的类作为类型参数
- 不命名构造函数和析构函数上的类型错误
- 具有自定义构造函数 (C++) 的类型的动态数组分配
- C++方法是否可以根据传递给构造函数的参数具有不同的返回类型?
- 创建类类型的动态分配数组,其中类不得具有默认构造函数
- 初始化自定义类型构造函数的数组
- OpenGL着色器错误C1068:类型构造函数中的数据过多
- Lambda 闭包类型构造函数
- 仅当基础类型具有模板类型构造函数时,才实现这些构造函数
- 模板类的构造函数在使用 new 关键字时调用类型构造函数
- 如何强制函数参数为相同类型,并且不允许使用类型构造函数与给定类型匹配
- 模板类型构造函数参数
- 它们是c++中的类型构造函数
- 解析C++类型构造函数