草庐IT

Wzero-as-null-pointer-constant

全部标签

c++ - std::static_pointer_cast 与 static_cast<std::shared_ptr<A>>

我有一个类层次结构,其中B源自A像这样:classA:publicstd::enable_shared_from_this{};classB:publicA{voidf(){//thecodebelowcompilesstd::shared_ptrcopyOfThis=std::static_pointer_cast(shared_from_this());//thecodebelowdoesnotstd::shared_ptrcopyOfThis=static_cast>(std::make_shared(shared_from_this()));}};所以实际上我想了解为什么我不能

c++ - 有人可以打破这条线 gcc -E -dM - </dev/null

刚刚遇到这个让我惊呆了的人:gcc-E-dM-这部分让我感到困惑:- 最佳答案 这给出了gcc中所有预定义宏的列表。-E表示运行预处理器。-dM表示从预处理器中转储预定义的宏。-用于从标准输入读取,而/dev/null仅提供一个空源文件。 关于c++-有人可以打破这条线gcc-E-dM- https://stackoverflow.com/questions/1529051/

c++ - NULL 指针与 static_cast 的兼容性

Q1。为什么在static_cast中使用NULL指针会导致崩溃,而dynamic_cast和reinterpret_cast会返回NULL指针?问题发生在类似于下面给出的方法中:voidA::SetEntity(B*pEntity,intiMyEntityType){switch(iMyEntityType){caseENTITY1:{Set1(static_cast(pEntity));return;}caseENTITY2:{Set2(static_cast(pEntity));return;}caseENTITY3:{Set3(static_cast(pEntity));ret

Springboot在编写CRUD时,访问对应数据函数返回null

1.我遇到了什么问题我在学习springboot,其中在编写CRUD时发现访问数据的函数执行下去返回值是null但是其它部分正常。下面是我的错误代码pojopublicclassBot{@TableId(type=IdType.AUTO)privateIntegerid;privateIntegeruser_id;privateStringname;privateStringdescription;privateStringcontent;privateIntegerrating;@JsonFormat(pattern="yyyy-MM-ddHH:mm:ss")privateDatecreat

C++11 decltype : How to declare the type that a pointer points to?

我有以下代码:#includeintmain(){int*a=newint(2);std::unique_ptrp(a);}导致这些错误信息:Infileincludedfroma.cpp:1:Infileincludedfrom/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/memory:81:/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/

C++ is_member_pointer 实现

在c++标准库中,is_member_pointer实现为templatestruct__is_member_pointer_helper:publicfalse_type{};templatestruct__is_member_pointer_helper:publictrue_type{};///is_member_pointertemplatestructis_member_pointer:public__is_member_pointer_helper::type>::type{};有人可以解释一下_Cp是如何推导出来的吗?它像魔术一样工作。 最佳答

c++ - C++ 中 C# 'as' 命令的等价物?

在C#中,您可以使用as来转换类型或获取null:Objecto=Whatever();Strings=oasString;在C++中是否有类似的简单方法来实现此目的?如果重要的话,我正在使用VisualStudio2010。[更新]:请记住,转换和使用as之间有一个非常重要的区别。如果类型不匹配,转换(至少在C#中)将抛出异常:Objecto=null;Strings=(String)o;//Willcrash. 最佳答案 在C++中,如果您有一个层次结构,其中Object是父对象而String是子对象,这将是一个dynamic_

c++ - C 和 C++ : Array element access pointer vs int

如果您执行myarray[i]或将myarray[i]的地址存储在指针中,是否存在性能差异?编辑:这些指针都是在我的程序中一个不重要的步骤中计算出来的,性能不是标准。在关键部分,指针保持静态并且不被修改。现在的问题是这些静态指针是否比一直使用myarray[i]更快。​​ 最佳答案 对于这段代码:intmain(){inta[100],b[100];int*p=b;for(unsignedinti=0;i在g++中使用-O3优化构建时,语句:a[i]=i;产生汇编输出:mov%eax,(%ecx,%eax,4)和这个声明:*p++=

c++ - std::ofstream == NULL 不会为 -std=gnu++11 编译,任何解决方法?

考虑以下代码:std::ostreamfile;if(file==NULL)std::cout它在通过-std=gnu11(GCC5.2的默认值)或仅使用时完美编译gcccode.cpp-oa.out.不过,-std=gnu++11失败了:nomatchfor‘operator==’(operandtypesare‘std::ofstream{akastd::basic_ofstream}’and‘longint’)`最简单的解决方法是什么?详细信息:我必须使用std=gnu++11才能访问shared_ptr定义。此外,我的一些代码是自动生成的,修改生成器会付出合理的努力-所以我想知

c++ - "' void* ' is not a pointer-to-object type"在没有 void* 的代码中?

我的代码有问题。在Xcode或使用C++11编译器中,此代码运行良好。但是,当我将此代码提交给在线法官时,判决显示“编译错误”。我认为他们使用的是C++4.7.1编译器,当我尝试编译它(使用Ideone)时,它说:prog.cpp:Infunction'voidprintArray(int)':prog.cpp:27:error:'void*'isnotapointer-to-objecttypeprog.cpp:27:error:'void*'isnotapointer-to-objecttypeprog.cpp:27:error:'void*'isnotapointer-to-ob