gpt4 book ai didi

c++ - 自定义无序集哈希函数

转载 作者:行者123 更新时间:2023-11-28 07:16:31 25 4
gpt4 key购买 nike

我第一次为我的数据结构类使用无序集。当我尝试在我们学校的服务器上运行这段代码时,它告诉我它的架构错误。这是我的主要代码(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.

应该注意的是,当模板化为整数类型时,同样的代码可以正常工作

最佳答案

您需要针对要在其上运行的机器类型编译程序。您为此编译的机器类型与您学校的计算机不匹配。

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

您可以在 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++ 您正在构建一个中间对象,而不是最终对象。

关于c++ - 自定义无序集哈希函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20155236/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com