jjzjj

static_warning

全部标签

c++ - 使用 'g++' 结果为 "warning: will never be executed"

我继承了一个C++项目。我在RHELbuild5.5与GCC4.1.2通过makefile。该项目很大(数百个文件),总的来说代码还不错。然而,在编译过程中,我经常收到一个GCC警告,上面写着(prefix"/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2"):/bits/allocator.h:Inconstructor‘std::allocator::allocator()[with_Tp=char]’:/bits/allocator.h:97:warning:willneverbeexecuted

c++ - 为什么编译器在我定义了 _CRT_SECURE_NO_WARNINGS 之后仍然警告我不安全的 strtok?

我正在使用适用于Windows桌面的VisualStudioExpress2012。我总是出错ErrorC4996:'strtok':Thisfunctionorvariablemaybeunsafe.Considerusingstrtok_sinstead.Todisabledeprecation,use_CRT_SECURE_NO_WARNINGS.Seeonlinehelpfordetails.当我尝试构建以下内容时:#include"stdafx.h"#define_CRT_SECURE_NO_WARNINGS#include#includeusingnamespacestd;

c++ - GCC 选项 : warning on non-void functions without a return statement

如果存在具有非空返回值但在其定义中不包含return语句的函数,是否有生成错误/警告的GCC/g++选项?例如:intadd(inta,intb){a+b;} 最佳答案 -Wreturn-type.它由-Wall(您应该始终与-Werror-Wextra一起运行)启用。 关于c++-GCC选项:warningonnon-voidfunctionswithoutareturnstatement,我们在StackOverflow上找到一个类似的问题: https:

c++ - g++ 表示 : warning: statement has no effect for shift bits operators

我正在实现alkhwarizmi算法。没错,但我的g++编译器不喜欢移位运算符:>>和当我编译它时,我得到这个输出:>g++-Wall-std=c++0x-o"Al-khwarizmialgorithm.o""Al-khwarizmialgorithm.cpp"(indirectory:/home/akronix/workspace/Algorithms)>Al-khwarizmialgorithm.cpp:Infunction‘intalkhwarizmi(int,int)’:Al-khwarizmialgorithm.cpp:31:9:warning:statementhasnoe

C++ : Initializing base class constant static variable with different value in derived class?

我有一个带有常量静态变量a的基类A。我需要类B的实例对静态变量a具有不同的值。这怎么能实现,最好是静态初始化?classA{public:staticconstinta;};constintA::a=1;classB:publicA{//???//Howtoset*a*toavaluespecifictoinstancesofclassB?}; 最佳答案 你不能。所有派生类共享一个静态变量实例。 关于C++:Initializingbaseclassconstantstaticvaria

c++ - 在派生对象到基类的 "this"指针上使用 static_cast 的问题

这是取自EffectiveC++3ed的一个例子,它说如果这样使用static_cast,对象的基础部分被复制,并且调用从该部分调用。我想了解幕后发生的事情,有人会帮忙吗?classWindow{//baseclasspublic:virtualvoidonResize(){}//baseonResizeimpl};classSpecialWindow:publicWindow{//derivedclasspublic:virtualvoidonResize(){//derivedonResizeimpl;static_cast(*this).onResize();//cast*thi

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++ - 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

c++ - static_if 会弃用模板特化吗?

像这样的一些常用模板特化:templateclassC{voidcommon(){...}voidf2=delete;};templateclassC{voidcommon(){...}voidf1(){...}};可以用static_if表示作为:templateclassC{voidcommon(){...}static_if(std::is_same::value){voidf1(){...}}else{voidf2()=delete;}}这些是直接竞争的功能吗?模板特化可以做static_if做不到的事情吗?看起来static_if可以做模板特化可以做的一切,甚至更多。顺便说一

c++ - 未解析的外部符号 "private: static int Math::result"

这个问题在这里已经有了答案:Whatisanundefinedreference/unresolvedexternalsymbolerrorandhowdoIfixit?(38个答案)关闭8年前。这是我的类定义:#includeusingnamespacestd;classMath{private:staticintresult;public:staticintadd(inta,intb){result=a+b;returnresult;};};这是主要的:#include#include"Amin.cpp"usingnamespacestd;intmain(){Math::add(2