gpt4 book ai didi

c++ - 使用 boost 多精度库的问题

转载 作者:搜寻专家 更新时间:2023-10-31 01:01:14 26 4
gpt4 key购买 nike

我正在尝试编写一个基本转换程序,该程序将适用于超出 C++ 的 long long 整数限制的数字。我正在尝试使用 boost 多精度库,但还没有走得很远。

我试过编译以下内容:

#include <boost/multiprecision/gmp.hpp>
#include <iostream>
#include <string>
#include <stdio.h>

namespace boost{ namespace multiprecision{

class gmp_int;

typedef number<gmp_int > mpz_int;

}} // namespaces
using namespace boost::multiprecision;
int main(int argc, const char * argv[]) {
mpz_int seed = 18446744073709551615;

std::cout << seed;
return 0;
}

并收到以下错误:

    main.cpp:17:20: error: reference to 'gmp_int' is ambiguous
typedef number<gmp_int > mpz_int;
^


main.cpp:15:11: note: candidate found by name lookup is
'boost::multiprecision::gmp_int'
class gmp_int;
^

/usr/local/boost_1_57_0/boost/multiprecision/gmp.hpp:2157:40: note: candidate
found by name lookup is 'boost::multiprecision::gmp_int'
using boost::multiprecision::backends::gmp_int;
^

main.cpp:17:20: error: reference to 'gmp_int' is ambiguous
typedef number<gmp_int > mpz_int;
^

main.cpp:15:11: note: candidate found by name lookup is
'boost::multiprecision::gmp_int'
class gmp_int;
^

/usr/local/boost_1_57_0/boost/multiprecision/gmp.hpp:2157:40: note: candidate
found by name lookup is 'boost::multiprecision::gmp_int'
using boost::multiprecision::backends::gmp_int;
^

main.cpp:17:38: error: typedef redefinition with different types ('number<class
boost::multiprecision::gmp_int>' vs 'number<struct
boost::multiprecision::backends::gmp_int>')
typedef number<gmp_int > mpz_int;
^

/usr/local/boost_1_57_0/boost/multiprecision/gmp.hpp:2214:34: note: previous
definition is here
typedef number<gmp_int > mpz_int;
^

main.cpp:22:2: error: reference to 'gmp_int' is ambiguous
gmp_int seed = 18446744073709551615;
^

/usr/local/boost_1_57_0/boost/multiprecision/gmp.hpp:2157:40: note: candidate
found by name lookup is 'boost::multiprecision::gmp_int'
using boost::multiprecision::backends::gmp_int;
^

main.cpp:15:11: note: candidate found by name lookup is
'boost::multiprecision::gmp_int'
class gmp_int;
^

main.cpp:32:18: 错误:使用了未声明的标识符“种子” std::cout << 种子; ^ 产生了 5 个错误。

我知道我一定犯了一些非常基本的错误,但我没有成功地修正它们。任何帮助将不胜感激。

我有一个简单的程序可以使用 #include <boost/lambda/lambda.hpp> , 所以我相当确定 boost 安装正确。

最佳答案

看起来您从文档中复制了错误的位:http://www.boost.org/doc/libs/1_57_0/libs/multiprecision/doc/html/boost_multiprecision/tut/ints/gmp_int.html

显示的是引用摘要,而不是用法概要。显示的类型已经存在。

少即是多的明显例子:

Live On Coliru

#include <boost/multiprecision/mpfr.hpp>
#include <iostream>

int main() {
boost::multiprecision::mpz_int seed = 18446744073709551615ull;
std::cout << seed;
}

关于c++ - 使用 boost 多精度库的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29524881/

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