背景:我從Java世界來到,而我對C++或Qt相當陌生。C++ unordered_map與矢量作爲鍵一起使用時失敗
爲了與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: error: collect2: ld returned 1 exit status
任何想法的問題來源?
在此先感謝。
你需要一個散列函數,它需要一個'vector' –
這不是運行時失敗。 –
@SethCarnegie這就是我雖然也遇到了問題。但是,在我看來,像vector這樣基本的類應該有一個默認的散列函數。如果情況並非如此,你能否向我解釋如何提供或向我提供某些材料。謝謝! –