草庐IT

member-enumeration

全部标签

c++警告: enumeration value not handled in switch [-Wswitch]

我正在尝试编译以下代码而没有警告:while(window.pollEvent(event)){switch(event.type){casesf::Event::Closed:window.close();break;casesf::Event::KeyPressed:if(event.key.code==sf::Keyboard::Escape)window.close();if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space))particleSystem.fuel(200/**window.getFrameTime()*/);if(

c++警告: enumeration value not handled in switch [-Wswitch]

我正在尝试编译以下代码而没有警告:while(window.pollEvent(event)){switch(event.type){casesf::Event::Closed:window.close();break;casesf::Event::KeyPressed:if(event.key.code==sf::Keyboard::Escape)window.close();if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space))particleSystem.fuel(200/**window.getFrameTime()*/);if(

c++ vector.push_back 错误: request for member 'push_back' . ..,属于非类类型 'vector(char, allocator(char)) ()()'

我将Cygwin与GCC一起使用,最终我想将字rune件读入字符vector,并使用此代码#include#include#includeusingnamespacestd;intmain(intargc,char*argv[]){vectorstring1();string1.push_back('a');return0;}生成此编译时错误:main.cpp:Infunctionintmain(int,char**)':main.cpp:46:error:requestformemberpush_back'instring1',whichisofnon-classtypestd::v

c++ vector.push_back 错误: request for member 'push_back' . ..,属于非类类型 'vector(char, allocator(char)) ()()'

我将Cygwin与GCC一起使用,最终我想将字rune件读入字符vector,并使用此代码#include#include#includeusingnamespacestd;intmain(intargc,char*argv[]){vectorstring1();string1.push_back('a');return0;}生成此编译时错误:main.cpp:Infunctionintmain(int,char**)':main.cpp:46:error:requestformemberpush_back'instring1',whichisofnon-classtypestd::v

c++ - 公共(public)算子新建,私有(private)算子删除 : getting C2248 "can not access private member" when using new

一个类有重载的操作符new和delete。new是公开的,delete是私有(private)的。在构造该类的实例时,出现以下错误:pFoo=newFoo(bar)example.cpp(1):错误C2248:'Foo:operatordelete':无法访问在类'Foo'中声明的私有(private)成员但是这里没有调用delete,那么编译器扭曲的头脑中发生了什么?:)错误的原因是什么?是否可以在不借助成员CreateInstance函数的情况下解决问题? 最佳答案 当您执行newFoo()时,会发生两件事:首先调用operat

c++ - 公共(public)算子新建,私有(private)算子删除 : getting C2248 "can not access private member" when using new

一个类有重载的操作符new和delete。new是公开的,delete是私有(private)的。在构造该类的实例时,出现以下错误:pFoo=newFoo(bar)example.cpp(1):错误C2248:'Foo:operatordelete':无法访问在类'Foo'中声明的私有(private)成员但是这里没有调用delete,那么编译器扭曲的头脑中发生了什么?:)错误的原因是什么?是否可以在不借助成员CreateInstance函数的情况下解决问题? 最佳答案 当您执行newFoo()时,会发生两件事:首先调用operat

c++ - 我可以忽略 gcc 警告 : ‘Foo::m_bar’ should be initialized in the member initialization list [-Weffc++]

structBar{Bar(){}};structFoo{Foo()=default;Barm_bar;};intmain(){Foofoo;}当使用C++11default关键字和gcc警告-Weffc++时,gcc输出:warning:‘Foo::m_bar’shouldbeinitializedinthememberinitializationlist[-Weffc++]忽略此警告是否安全?我应该向gcc提交错误吗? 最佳答案 您可以忽略或抑制警告。这是对有效C++指南之一的误解。该指南说更喜欢初始化而不是赋值,但在您的示例中

c++ - 我可以忽略 gcc 警告 : ‘Foo::m_bar’ should be initialized in the member initialization list [-Weffc++]

structBar{Bar(){}};structFoo{Foo()=default;Barm_bar;};intmain(){Foofoo;}当使用C++11default关键字和gcc警告-Weffc++时,gcc输出:warning:‘Foo::m_bar’shouldbeinitializedinthememberinitializationlist[-Weffc++]忽略此警告是否安全?我应该向gcc提交错误吗? 最佳答案 您可以忽略或抑制警告。这是对有效C++指南之一的误解。该指南说更喜欢初始化而不是赋值,但在您的示例中

c++ - 强制部分运营商成为成员(member)的理由

C++中有4个运算符可以重载,但不能作为独立(也称为非成员、独立)函数重载。这些运算符是:运算符=运算符()运算符->运算符[]Thisthread完美地解释了禁止operator=成为非成员函数的理由。对其他三个有什么想法吗? 最佳答案 原贴中提到的四个运算符,=、()、->和[],确实必须实现为非静态成员函数(分别由C++98§13.5.3/1、§13.5.4/1、§13.5.5/1和§13.5.6/1)。BjarneStroustrup的基本原理是,正如我从之前关于该主题的辩论中所记得的那样,在语言中保持一些理智,即,无论其他

c++ - 强制部分运营商成为成员(member)的理由

C++中有4个运算符可以重载,但不能作为独立(也称为非成员、独立)函数重载。这些运算符是:运算符=运算符()运算符->运算符[]Thisthread完美地解释了禁止operator=成为非成员函数的理由。对其他三个有什么想法吗? 最佳答案 原贴中提到的四个运算符,=、()、->和[],确实必须实现为非静态成员函数(分别由C++98§13.5.3/1、§13.5.4/1、§13.5.5/1和§13.5.6/1)。BjarneStroustrup的基本原理是,正如我从之前关于该主题的辩论中所记得的那样,在语言中保持一些理智,即,无论其他