草庐IT

with_static

全部标签

c++ - C++ 语言标准对 static_cast 如何处理减小整数的大小有何规定?

我想知道C++语言标准针对以下情况指定的规则:longx=200;shorty=static_cast(x);y是否保证为200,还是标准将其留给实现来决定?各种编译器对标准的遵守程度如何? 最佳答案 在本例中为static_cast是一个“显式类型转换”。该标准对4.7/3“积分转换”中的积分转换有这样的说法:Ifthedestinationtypeissigned,thevalueisunchangedifitcanberepresentedinthedestinationtype(andbit-fieldwidth);othe

c++ - 错误 MSB6006 : "cmd.exe" exited with code 1 running QT application

我使用visualstdio2012命令提示符编译了QT5.0.1。当我创建控制台应用程序时,一切都很好并且可以正常工作,但是当我创建QT应用程序时,它会抛出此错误:Error1errorMSB6006:"cmd.exe"exitedwithcode1(已安装QTvisualstdioqt-vs-addin-1.2.0) 最佳答案 打开详细构建输出以查找您的确切问题,工具->选项->项目和解决方案->构建和运行->构建输出和构建日志详细信息。我的问题是错误地使用了“CONST”。(CleanandRebuild似乎可以暂时解决问题,

c++ - static_assert 不会立即中断编译

代码示例:templatestructSUM{static_assert(x>=0,"Xmustbegreaterorequalto0");enum{VALUE=x+SUM::VALUE};};templatestructSUM{enum{VALUE=0};};intmain(){std::cout::VALUE为什么编译器不会在第一个static_assert时中断编译,而是继续工作直到达到最大实例化深度?Invoking:GCCC++Compilerg++-O0-g3-Wall-c-fmessage-length=0-std=c++11-MMD-MP-MF"src/Main.d"-

c++ - static_cast 从基析构函数到指向派生类的指针的安全性

这是问题的变体DowncastingusingtheStatic_castinC++和Safetyofinvaliddowncastusingstatic_cast(orreinterpret_cast)forinheritancewithoutaddedmembers关于~B中的行为,我不清楚标准中的短语“B实际上是D类型对象的子对象,结果指针指向D类型的封闭对象”。如果在~B中转换为D,此时它仍然是子对象吗?以下简单示例显示了问题:voidf(B*b);classB{public:B(){}~B(){f(this);}};classD:publicB{public:D(){}};s

c++ - constexpr if with initializer 由标准保证吗? 'constexpr(constexpr auto x = f(); x) { }'

我找不到任何关于新C++17if初始化语法的信息和“constexprif”在:http://open-std.org/JTC1/SC22/WG21/docs/papers/2016/p0128r1.html不过,Clang-HEAD支持该语法...constexprautof(){returntrue;}intmain(){ifconstexpr(constexprautox=f();x){}}在线代码在这里->http://melpon.org/wandbox/permlink/dj3a9ChvjhlNc8nr是constexprif带有标准保证的初始值设定项,如constexpr

c++ - 在 C++ 中检测运算符是否存在和可调用(考虑 static_asserts)

给定2种类型T和U我想检测是否可以调用operator*在对象之间(即是否可以写t*u,其中t是T类型,u是U类型)我正在使用c++detectionidiom但由于它在我的编译器中还不可用,所以我自己实现了它structnonesuch{nonesuch()=delete;~nonesuch()=delete;nonesuch(nonesuchconst&)=delete;voidoperator=(nonesuchconst&)=delete;};namespacedetail{templateclassOp,class...Args>structdetector{usingval

c++ - Pimpl with unique_ptr : Why do I have to move definition of constructor of interface to ".cpp"?

只要我不将构造函数(B)的定义移动到标题B.h中,代码就可以工作。B.hclassImp;//imp;B();//B.cpp#include"B.h"#include"Imp.h"B::B(){}~B::B(){}Imp.hclassImp{};Main.cpp(编译我)#include"B.h"Error:deletionofpointertoincompletetypeError:useofundefinedtype'Imp'C2027我能以某种方式理解必须将析构函数移动到.cpp,因为可能会调用Imp的解构:-deletepointer-of-Imp;//somethinglik

c++ - 检测带有函数失败 static_assert 的成语

有没有办法使用detectionidiom(或其他方法)测试一个函数是否对给定的模板参数有效,如果它由于static_assert?而失败下面的示例说明了foo的有效性(失败的返回类型计算)按预期被检测到,但是bar的有效性(失败的static_assert)不是。#include#includetemplateusingvoid_t=void;templateclassOp,class...Args>structdetector:std::false_type{};templateclassOp,class...Args>structdetector>,Op,Args...>:std

UF_UI_select_with_single_dialog()通过单选对话框选择单个对象。对象可以通过光标或输入名称进行选择。对象被突显出来。

 intresponse=0;//返回用户操作类型,点了哪一种返回取消或者确定 tag_tobjtag=NULL_TAG;//输出选择对象tag; doublecursor[3];//输出光标位置 tag_tview_tag=NULL_TAG;//输出视图tag; UF_UI_select_with_single_dialog("请选择一个对象","获取对象类型",UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY,NULL,NULL,&response,&objtag,cursor,&view_tag); if(objtag!=NULL) { inttype=0; intsu

c++ - 为什么在头文件中声明 "static const"成员会导致链接器错误?

我有一个这样的类声明(.h文件):structMyClass{staticconstuint32_tSIZE=sizeof(MyType);};将我的程序链接在一起时,出现MyClass::SIZE的链接器错误。nm确认符号未定义。http://forums.devshed.com/c-programming-42/linker-errors-undefined-reference-to-static-member-data-193010.html似乎解决了我的问题,表明“类静态对象也必须像普通全局变量一样在任何函数或类之外声明。”我有两个问题:这个解释对我的情况有效吗?如果是这样,您