草庐IT

int_types

全部标签

C++1y/C++14 : Converting static constexpr array to non-type template parameter pack?

假设我有一个静态存储持续时间的constexpr数组(已知范围):constexprTinput[]=/*...*/;我有一个需要打包的输出类模板:templatestructoutput_template;我想像这样实例化output_template:usingoutput=output_template;一种方法是:templatestructmake_output_template{templatestaticconstexproutput_templatef(std::index_sequence){return{};};usingtype=decltype(f(std::m

c++ - 错误 : invalid operands of types 'int' and '<unresolved overloaded function type>' to binary 'operator<<'

我想获取z_Data的第48个字符的第6位{charc=pPkt->z_Data[47];//thisz_Dataisacharbufferstd::cout>3)&1>4)&1>5)&1 最佳答案 优先级高于&,所以你需要:std::cout>3)&1)>4)&1)>5)&1) 关于c++-错误:invalidoperandsoftypes'int'and''tobinary'operator https://stackoverflow.com/questions/246

c++ - 如何正确地将 time_t 转换为 long int?

我仍在学习C++中的类型转换,目前我正在做这件事longintt=time(NULL);我正在使用VS2013并注意到从“time_t”到“long”警告的转换,所以我想我应该将其强制转换为看起来像;longintt=static_casttime(NULL);然而,这还行不通,但结合静态转换和C风格转换仍然有效longintt=static_cast(time(NULL));我只是想知道是否有人可以帮助阐明这一点? 最佳答案 time(NULL)不是强制转换而是返回time_t的函数调用.自time_t与longint不完全相同的

c++ - unsigned int 到 unsigned long long 定义明确吗?

我想看看当unsignedlonglong被赋值给unsignedint时幕后发生了什么。我制作了一个简单的C++程序来试用它,并将所有io移出main():#include#includevoidusage(){std::cout\n";exit(0);}voidatoiWarning(intfoo){std::cout生成的程序集为main生成了这个:0000000000400950:400950:55push%rbp400951:4889e5mov%rsp,%rbp400954:4883ec20sub$0x20,%rsp400958:897decmov%edi,-0x14(%rb

c++ - 散列任意精度值(boost::multiprecision::cpp_int)

我需要以任意精度获取一个值的散列值(来自Boost.Multiprecision);我用cpp_int后端。我想出了以下代码:boost::multiprecision::cpp_intx0=1;constautoseed=std::hash{}(x0.str());我不需要代码尽可能快,但我发现对字符串表示进行哈希处理非常笨拙。所以我的问题是双重的:保持任意精度,我可以更有效地散列值吗?也许我不应该坚持保持任意精度,我应该转换成一个我可以轻松散列的double(不过,我仍然会使用任意精度值进行哈希表所需的比较)? 最佳答案 您可以

c++ - QMetaType::Float 不在 QVariant::Type 中

我有一个运行良好的应用程序,但它不是在打开警告的情况下编译的。我正在尝试将其重新打开并整理它们,但没有关于如何解决此问题的想法。我有:QVariantsomeVarQVariant::TypevariantType=someVar.type();switch(variantType){caseQMetaType::QString:doSomething1();break;caseQMetaType::Float:doSomething2();break;}并收到此警告/错误:error:casevalue‘135’notinenumeratedtype‘QVariant::Type’[

C++ : union of two types without virtual base class inheritance

是否可以在不手动创建交集类型的情况下创建两种类型的并集?问题是在我的上下文中交集类是完全没有意义的,所以创建它会使代码用户感到困惑。我的实际案例:我正在描述一个数字硬件模拟器,它是许多模块的分层树状结构:classport;classmodule0{porta,b,c;}classmodule1{portc,d,e;}我需要创建这两种类型的union:classtop_level_module{porta,b,c,d,e;}我想应该有一些技术来创建union类型(这是我要问的问题):classtop_level_module:union_type{//porta,b,c,d,e;}但是

c++ - 为什么采用 int 的函数重载优于采用 unsigned char 的函数重载?

考虑这个程序:#includeusingnamespacestd;voidf(unsignedcharc){cout这会打印出97,表明选择的f()重载是采用int的重载。我觉得这很奇怪;直觉上unsignedchar不是更适合char吗? 最佳答案 wouldn'tintuitivelyanunsignedcharbeabettermatchforachar?嗯,我想,但不是根据标准。根据[conv.prom]p1:Aprvalueofanintegertypeotherthanbool,char16_­t,char32_­t,o

c++ - shared_ptr 中对 const int 的 undefined reference

我有一个配置类//config.hppclassConfig{public:staticconstexprinta=1;staticconstexprintb=1;}并包含在main.cpp中//main.cpp#include"config.hpp"intmain(){std::coutstream=std::make_shared(Config::a);//compileerror}编译器说未定义对Config::a的引用它在使用cout时有效,但在shared_ptr构造函数中时无效。我不知道为什么会这样。 最佳答案 请注意s

c++ - int() 和 int(*)() 有什么区别?

我正在尝试创建一个识别函数的类模板,我可以在其中识别函数何时专门化R(*)()的类模型,但在std::function你可以申报return_type(),和std::is_same.::value为零。这是什么int()statementmean和int()有什么区别和int(*)()?更新:所以int()是函数声明或函数类型并且int(*)()是指向函数的指针。但是waht是int(std::string::)()的类型函数?类似于intstd::string::(),或喜欢std::functionint(conststd::string&)?如何让这个程序输出1?#includ