草庐IT

best_common_numeric_type

全部标签

C++ vector::size_type:有符号与无符号;整数与长

我一直在通过在不同平台上编译我的应用程序来对其进行一些测试,从64位系统到32位系统的转变暴露出许多问题。我大量使用vector、字符串等,因此需要对它们进行计数。但是,我的函数也使用32位无符号数,因为在许多情况下我需要显式使用正整数。我在处理看似简单的任务时遇到了问题,例如std::min和std::max,它们可能更系统化。考虑以下代码:uint32_tgetmax(){return_vecContainer.size();}看起来很简单:我知道一个vector不能有负数的元素,所以返回一个无符号整数是完全合理的。voidsetRowCol(constuint32_t&r_row

c++ - "lightweight type categorization idiom"的最简单实现?

我的目标是实现一个检测嵌套using是否存在的谓词别名(或typedef)充当轻量级标签以指示类具有某些属性(用于泛型编程)。例如,has_my_tag谓词的行为应如下所示:structA{usingmy_tag=void;};structB{};intmain(){static_assert(has_my_tag::value,"");//evaluatetotrueifmy_tag=voidispresentstatic_assert(!has_my_tag::value,"");//falseotherwise}用户@JoelFalcou称其为“轻量级类型分类成语”并在thisa

c++ - 编译错误 : base operand of ‘->’ has non-pointer type ‘Token’

我在尝试编译我的C++代码时遇到标题中提到的错误。我无法理解我在这里做错了什么。编译器在我执行booloperator==(Token)函数时出现问题。我认为这是使运算符(operator)重载的方法。关于为什么编译器不喜欢我提到的任何线索this->terminal还是this->lexeme?classToken{public:tokenTypeterminal;std::stringlexeme;Token*next;Token();booloperator==(Token&t);private:intlexemelength,line,column;};boolToken::o

c++ - knnMatchImpl 中的断言失败 (queryDescriptors.type() == trainDescCollection[0].type()),

当使用BOWImgDescriptorExtractor和DescriptorExtractor作为SIFT和DescriptorMatcher作为ButeForce我我收到错误信息OpenCVError:Assertionfailed(queryDescriptors.type()==trainDescCollection[0].type())inknnMatchImpl,我有什么错误。当我尝试计算时例如。bowide->compute(img,keypoints,response_hist); 最佳答案 我在使用带有BFMatc

c++ - "Use of undefined type"带有 unique_ptr 以转发声明的类和默认移动构造函数/赋值

在下面的代码中,是避免编译错误并在A.cpp中手动包含B.h实现移动构造函数/赋值的唯一方法吗?//A.h#includeclassB;//implementationsomewhereinB.h/B.cppclassA{public:A()=default;~A()=default;A(constA&)=delete;A&operator=(constA&)=delete;A(A&&)=default;A&operator=(A&&)=default;private:std::unique_ptrm_b;};VisualStudio2015给出“错误C2027:使用未定义类型”,因为

c++ - 如何比较 time_t 和 std::filesystem::file_time_type

我正在将一些代码从boost::filesystem转换到std::filesystem。以前使用的代码boost::filesystem::last_write_time()它返回一个time_t,因此直接与我已经持有的time_t对象进行比较是微不足道的。顺便说一句,我持有的这个time_t是从很久以前保存的文件内容中读取的,所以我坚持使用这种“自unix纪元以来的时间”类型。std::filesystem::last_write_time返回std::filesystem::file_time_type.是否有可移植的方法将file_time_type转换为time_t,或者以其

Apache Commons Email在邮件发送中的应用

第1章:简介大家好,我是小黑,今天咱们聊聊ApacheCommonsEmail这个库,它在发送邮件方面可谓是小而美的利器。ApacheCommonsEmail基于JavaMailAPI,但它提供了更简洁、更易用的接口,让咱们在处理电子邮件发送时可以省去不少麻烦。为什么选它呢?首先,它轻量,无需深入研究复杂的JavaMailAPI就能快速上手;其次,它功能全面,不论是发送普通文本邮件、HTML邮件,还是带附件的邮件,它都能轻松应对。第2章:环境搭建好,咱们先说说怎么搭建起ApacheCommonsEmail的环境。首先,得确保你的Java环境搭建好了。ApacheCommonsEmail支持Ja

c++ - 错误 : Field has an incomplete type

quaternion.h:15:错误:字段“v”的类型不完整嗨!我陷入了一个我似乎无法解决的错误。下面是我的代码:#ifndefQUATERNION_H#defineQUATERNION_H#include"vec3.h"classVec3;classQuaternion{public:Quaternion(Vec3v);Quaternion(doublew,Vec3v);Vec3v;我的Vec.h看起来像这样:#ifndefVEC3_H#defineVEC3_H#include"point.h"#include"quaternion.h"#includeclassQuaternion

c++ - std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n' ) 使用#include <Windows.h> 时出错

这个问题在这里已经有了答案:std::max-expectedanidentifier(6个答案)macro"max"requires2arguments,butonly1given(4个答案)关闭去年。在VisualStudio2010Pro中,我在max()上收到一个编译错误,指出“需要一个标识符”命令的一部分。似乎在windows.h头文件中有一个max(a,b)标识符和编译器想要使用它。我尝试使用#include也一样,但这并没有解决问题。有什么办法可以解决这个问题吗?

c++ - 'must have an argument of class or enumerated type'到底是什么意思

我有一个头文件和一个.cpp文件。我需要为我的.h文件编写函数,但在我完全完成骨架.cpp文件之前出现错误。金钱.h#ifndefMONEY_H#defineMONEY_H#include#includeusingnamespacestd;classMoney{public:Money(intdollars,intcents);Moneyoperator+(constMoney&b)const;Moneyoperator-(constMoney&b)const;Moneyoperator*(doublem)const;Moneyoperator/(doubled)const;voidp