gpt4 book ai didi

c++ - 在 C++ 中实现 map

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:21:43 27 4
gpt4 key购买 nike

出于某种原因,我需要一个从任意大数到 double 的映射,我尝试用 c++98(我必须这样做)和 Xcode 来实现它,但它不起作用:

#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include "gurobi_c++.h"
#include <sstream>
#include "boost/tuple/tuple.hpp"
#include "boost/tuple/tuple_comparison.hpp"
#include "boost/tuple/tuple_io.hpp"
#include <cmath>
#include <gmp.h>

using namespace std;
using namespace ::boost::tuples;
using namespace ::boost;

int main()
{
map<mpz_t, double>J;
mpz_t a,b,c,n;
string tempstring;
int xrange=5,yrange=5,component=5;

mpz_set_str(n,"11", 10);
J[n]=-1;

return 0;
}

显示的错误是:Array initializer must be an initializer list。有人可以帮我吗?谢谢:)

这是详细的错误页面: enter image description here enter image description here

最佳答案

我不知道 mpz_t 的细节。但是,它似乎是一个数组。

您可以通过定义一个类用作 map 中的键来解决这个问题。

我能够使用以下代码和 g++ 4.8.2 创建可执行文件。

#include <map>
using namespace std;

typedef int (mpz_t)[2];

struct MyKey
{
// Add a proper implementation of a constructor
// with mpz_t.
MyKey(mpz_t in) {}

// Add a proper implementation of copy constructor.
MyKey(MyKey const& copy) {}

// Add a proper implementation of assignment operator.
MyKey& operator=(MyKey const& rhs)
{
return *this;
}

bool operator<(MyKey const& rhs) const
{
// Add a proper implementation.
return false;
}

mpz_t n;
};

int main()
{
map<MyKey, double> J;
mpz_t n;
J[n] = 1.0;
return 0;
}

关于c++ - 在 C++ 中实现 map<mpz_t, double>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25224861/

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