草庐IT

Signed-off-by

全部标签

c++ - make_signed<unsigned long>::type 是 int?

我使用的是VisualStudio2010,下面的代码让我有些困惑:#includeautox=std::make_signed::type();x将是int类型,但我预计会很长。我知道VS10中的int和long都是4字节整数。但是即使一个signedlong装进一个int,int对我来说也不是unsignedlong对应的signedinteger类型。所以我的问题是:这是错误/技术错误还是标准规范允许这种结果? 最佳答案 C++1120.9.7.3[meta.trans.sign]描述了make_signed:IfTnames

c++ - 通过 const reference 或 by value 传递 int,有什么区别吗?

这个问题在这里已经有了答案:Isitcounter-productivetopassprimitivetypesbyreference?[duplicate](7个答案)关闭7年前。当我将int和double之类的原语传递给函数时,是通过constreference传递它们更好,还是通过值传递它们更好(假设我不更改变量的值)?intgetValueFromArray(intindex){//returnthevaluefromthearray}intgetValueFromArray(constint&index){//returnthevaluefromthearray}谢谢

C++ signed 和 unsigned int 与 long long 速度

今天,我注意到几个简单的按位和算术运算的速度在int之间有显着差异。,unsigned,longlong和unsignedlonglong在我的64位电脑上。特别是,对于unsigned,以下循环的速度大约是其两倍至于longlong,这是我没想到的。intk=15;intN=30;intmask=(1(完整代码here)以下是计时(以秒为单位)(对于g++-O、-O2和-O3):1.834207723(int)3.054731598(longlong)1.584846237(unsigned)2.201142018(unsignedlonglong)这些时间非常一致(即1%的差值)。

c++ - 警告 C4251 : needs to have dll-interface to be used by clients of class

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:std::vectorneedstohavedll-interfacetobeusedbyclientsofclass'Xwarning这是我在该组中的第一篇文章。我正在创建一个DLL并在应用程序的主文件中调用它。代码编译正常,但出现以下错误:warningC4251:'PNCBaseClass::m_vAvailChannelsFromRx':class'std::vector'needstohavedll-interfacetobeusedbyclientsofclass'PNCBaseClass'3>w

c++ - 为什么隐含的 "lambda to function pointer conversion"禁止静态成员的 "by reference"捕获?

C++11标准说(或者至少,我拥有的版本——不是最终版本):Theclosuretypeforalambda-expressionwithnolambda-capturehasapublicnon-virtualnon-explicitconstconversionfunctiontopointertofunctionhavingthesameparameterandreturntypesastheclosuretype’sfunctioncalloperator.我理解为什么无法从有状态lambda中获取函数指针,因为函数指针本身不能保存任何数据。但是当捕获的对象只是一个静态成员/静

c++ - std::is_signed 不适用于强类型枚举:int

谁能解释一下,为什么#include#includeusingnamespacestd;enumE:signedint{a=-1,b=1,};intmain(){std::cout()std::is_signed不做,锡上写的是什么?谢谢... 最佳答案 如果我们查看is_signed的文档它说:IfTisasignedarithmetictype,providesthememberconstantvalueequaltrue.Foranyothertype,valueisfalse.并且枚举不是算术类型,因此结果应该为假。来自C+

c++ - "signed char"和 "unsigned char"能否始终相互转换而不丢失数据?

在C++中,我们可以使用signedchar和unsignedchar,它们的大小相同但值的范围不同。在下面的代码中:signedcharsignedChar=-10;unsignedcharunsignedChar=static_cast(signedChar);signedChar=static_cast(unsignedChar);无论其原始值是多少,signedchar都会保留其值吗? 最佳答案 不,没有这样的保证。从signedchar到unsignedchar的转换是明确定义的,就像C++(和C)中的所有有符号到无符号整

c++ - std::is_signed<T> 和 std::numeric_limits<T>::is_signed 之间的区别?

两者都是std::is_signed和std::numeric_limits::is_signed应该给出关于T的签名的答案.为什么现在有两个符号指示符(即自C++11起)? 最佳答案 我敢猜测唯一的区别是如果std::numeric_limits专门用于用户定义的类型。这样的用户定义类型当然可以为is_signed提供自己的值。.但要求std::is_signed::value在这种类型上将始终返回false除非std::is_signed已独立特化。似乎std::is_signed的条件代表是is_arithmetic::val

C# Dll 导入失败 : "The application has failed to start because its side-by-side configuration is incorrect"

我有一个c#.net4应用程序,使用vs2010。我正在尝试导入一个c++dll(基于vs2005)。[DllImport("Card.dll")]我得到了失败:UnabletoloadDLL'Card.dll':Theapplicationhasfailedtostartbecauseitsside-by-sideconfigurationisincorrect.Pleaseseetheapplicationeventlogorusethecommand-linesxstrace.exetoolformoredetail.(ExceptionfromHRESULT:0x800736B

c++ - pass-by-reference & 和 * 之间的区别?

这个问题在这里已经有了答案:Passingamodifiableparametertoc++function(12个答案)关闭12个月前。按引用传递和使用C指针表示法有什么区别?voidsome_function(some_type¶m)和voidsome_function(some_type*param)谢谢