自定义无序集哈希函数

时间:2013-11-22 21:57:36

标签: c++ data-structures hash architecture unordered-set

我的数据结构类第一次使用无序集。当我尝试在学校服务器上运行此代码时,它告诉我它的架构是错误的。这是我的主要代码(RAJ.cpp):

#include<iostream>
#include<tr1/unordered_set>
#include "nflData.h"

using namespace std;
using std::tr1::unordered_set;
struct ihash: std::unary_function<NFLData, std::size_t> {
    std::size_t operator()(const NFLData& x) const
    {
        return x.getDown();//Currently just trying to return a value, will not be actual has function.
    }
};

int main(){
        string a = "20070906_NO@IND,1,46,42,IND,NO,2,6,27,(1:42) P.Manning pass deep left to M.Harrison for 27 yards TOUCHDOWN.,0,0,2007";
        string b = "20070906_NO@IND,1,46,42,IND,NO,3,6,27,(1:42) P.Manning pass deep left to [88'] for 27 yards TOUCHDOWN.,0,0,2007";
        string c = "20070906_NO@IND,1,46,42,IND,NO,,,27,A.Vinatieri extra point is GOOD Center-J.Snow Holder-H.Smith.,0,0,2007";

        unordered_set<NFLData, ihash> myset;
        cout << "\ninsert data a";
        myset.insert(NFLData(a));
        cout << "\ninsert data b";
        myset.insert(NFLData(b));
}

这是我在使用g ++成功编译后尝试运行时遇到的主要错误:

./test:  Exec format error. Wrong Architecture.

需要注意的是,这个相同的代码在模拟整数类型

时工作正常

1 个答案:

答案 0 :(得分:1)

您需要为要运行它的机器类型编译程序。您为此编制的计算机类型与学校的计算机不匹配。

如果学校在其服务器上安装了编译器,请使用它来编译您的程序。

您可以在UNIX,Linux和MacOS X下使用file命令查看您拥有的可执行文件类型。例如:

$ file /bin/ls    # on my Linux box
/bin/ls: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped

$ file /bin/ls    # on my MacBook Pro
/bin/ls: Mach-O usiversal binary with 2 architectures
/bin/ls (for architecture x86_64):      Mach-O 64-bit executable x86_64
/bin/ls (for architecture i386):        Mach-O executable i386

通常,不同的操作系统至少能够最低限度地识别外部系统的可执行文件,但并非总是如此。也就是说,它会识别它是外来的,但可能无法识别哪个外国系统。

如果您正在编译学校服务器上的代码,那么还有其他奇怪的事情正在发生。上面的file命令应该有助于排除某些事情。顺便说一句,您可以列出您正在使用的编译器标志,以及file的输出,其中包含适用的版本和不适用的版本。

要检查的另一件事:确保最终的编译步骤不包含g ++的-c标志。那个标志告诉G ++你正在构建一个中间对象,而不是最终对象。

相关问题