背景:我来自Java世界,对于C++或Qt还比较陌生。
为了尝试使用unordered_map,我编写了以下简单程序:
#include <QtCore/QCoreApplication>
#include <QtCore>
#include <iostream>
#include <stdio.h>
#include <string>
#include <unordered_map>
using std::string;
using std::cout;
using std::endl;
typedef std::vector<float> floatVector;
int main(int argc, char *argv[]) {
QCoreApplication a(argc, argv);
floatVector c(10);
floatVector b(10);
for (int i = 0; i < 10; i++) {
c[i] = i + 1;
b[i] = i * 2;
}
std::unordered_map<floatVector, int> map;
map[b] = 135;
map[c] = 40;
map[c] = 32;
std::cout << "b -> " << map[b] << std::endl;
std::cout << "c -> " << map[c] << std::endl;
std::cout << "Contains? -> " << map.size() << std::endl;
return a.exec();
}
很不幸,我遇到了以下错误,这并没有给我太多启示。甚至没有行号。
:-1: 错误:collect2:ld 返回 1
您有任何关于问题起源的想法吗?
vector<float>
的哈希函数。 - Seth Carnegie