草庐IT

INTEGRAL_CONSTANT

全部标签

c++ - 在 C++ 中显示为 "expression must have integral or enum type"的错误消息

我有以下代码,但在这个等式中出现错误:v=p*(1+r)^n.请帮我找出这个错误的原因。#include#includeusingnamespacestd;intmain(){floatv,p,r;intn;cout>p;cout>r;cout>n;v=(p)*(1+r)^n;//hereiamgettingerrormessageas"expressionmusthaveintegralorenumtype"cout 最佳答案 C++115.12-按位异或运算符exclusive-or-expression:and-express

c++ - constant 和 reinterpret cast 是否在编译时发生?

我读到过static_cast发生在编译时,dynamic_cast发生在运行时,因此比static_cast慢。dynamic_cast可以返回空指针(当与指针一起使用时)或以其他方式抛出错误的转换异常。我的问题是reinterpret_cast和const_cast是发生在编译时还是运行时?我认为解释转换发生在运行时,因为它的行为类似于dynamic_cast指示转换是否成功。我对么?const_cast是编译时间吗? 最佳答案 动态转换是唯一需要在运行时“计算”的。所有其他类型转换均在编译时计算。static_cast的机器代

c++ - 是否有针对 "conditional expression is constant"的 gcc 警告?

我继承了一个相当大的代码库,其中有人以某种方式编写了几个这样的条件:enum{FOO_TYPE_A,FOO_TYPE_B,FOO_TYPE_C,FOO_TYPE_D};voidbar(intfooType){if(fooType==FOO_TYPE_A||FOO_TYPE_B)//条件检查应该明确在哪里:if(fooType==FOO_TYPE_A||fooType==FOO_TYPE_B)在gcc中有没有警告我可以打开找到它们,类似于MSDN的C4127?具体来说,我使用的是AndroidNDKr9d。如果不是,为什么不呢?对于无意赋值,unsigned>0以及上述愚蠢行为,这似乎是

C++ 错误 : "Expression must have integral or enum type"

这个问题在这里已经有了答案:Whycan'ttheswitchstatementbeappliedtostrings?(22个答案)关闭8年前。我在下面的(不完整的)函数的switch语句中收到错误“表达式必须具有整数或枚举类型”。我盯着它看了一会儿,想不通这是怎么回事。非常感谢任何见解。std::stringCWDriver::eval_input(std::stringexpr){std::vectorparams(split_string(expr,""));std::stringoutput("");if(params.size()==0){output="Inputcanno

c++ - 如何表达 "the minimum integral type larger than T"?

假设我有一个整数类型T(有符号或无符号)。我想(在编译时)引用可以容纳的最小整数类型(有符号或无符号),比如说std::numeric_limits::max()加1(在非溢出意义上,我的意思是)。这样做的通用方法是什么? 最佳答案 对于无符号类型,这可以解决问题:templateconstexprunsignedsize_in_bits(){returnsizeof(T)*CHAR_BIT;}templateusingleast_larger_uint_t=typenameboost::uint_t()+1>::least;如果我

c++ - 为什么不允许优化器折叠 "constant context"?

__builtin_is_constant_evaluated是用于在clang和gcc的标准库中实现std::is_constant_evaluated的内置函数。在常量上下文中无效的代码通常也更难被优化器常量折叠。例如:intf(inti){if(__builtin_is_constant_evaluated())return1;else{int*ptr=newint(1);inti=*ptr;deleteptr;returni;}}由gcc-O3发出:f(int):subrsp,8movedi,4calloperatornew(unsignedlong)movesi,4movrd

c++ - std::is_unsigned 是否暗示 std::is_integral

如果我需要满足std::is_unsigned和std::is_integral的类型,我是必须同时检查还是只检查std::is_unsigned? 最佳答案 cppreference有此行is_unsigned(https://en.cppreference.com/w/cpp/types/is_unsigned):thisresultsintruefortheunsignedintegertypesandthetypeboolandinfalseforthesignedintegertypesandthefloating-poi

ios - TableView :dequeueReusableCellWithIdentifier issues with "global" constant

请留住我的头发,或指出我的(明显的)错误。我正在尝试在子类化的UITableViewController中使用UITableViewCellStyleSubtitle的UITableViewStyle。我在实现中定义了一个静态常量:staticNSString*constkAHCellIdentifier;在viewDidLoad中,我注册了一个tableView类:[self.tableViewregisterClass:[UITableViewCellclass]forCellReuseIdentifier:kAHCellIdentifier];然后在tableView:cellF

ios - SpriteKit : Stuttering during movement with constant velocity

我正在开发一款带有sprite套件的简单飞行游戏。一旦spaceship达到最大高度和速度,它就会以恒定速度继续飞行。我注意到spaceship在不断的飞行过程中会随机出现断断续续的情况。我已经在这里阅读了所有关于这个问题的帖子,但没有什么能真正帮助100%解决它。为了测试,我写了一个非常简单的游戏,它只包含一艘spaceship和一个简单的云(代码如下)。但是即使在这个非常简单的游戏中,spaceship仍然会卡顿。LOG表明,即使飞船以恒定速度飞行,飞船运动也不是随机恒定的。这就是口吃的原因。希望有人能帮我解决这个问题。感谢您的任何想法。Sprite套件、Objectivec、Xc

php - Laravel View Composer "Use of undefined constant"

整个晚上都在看,这一切看起来都很简单,但就是行不通!刚开始并尝试将变量放入View中。无论我做什么,我似乎都无法阅读它。路由.php:Route::get('/',function(){returnView::make('dashboard');});View::composer('dashboard',function($view){$view->with('links',"something");});仪表板.blade.php:@extends('base_view')@section('content')Allthestuff!{{links}}@stopbase_view.b