草庐IT

member-variables

全部标签

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++ - 多重继承 : same variable name

classA{protected:stringword;};classB{protected:stringword;};classDerived:publicA,publicB{};在Derived中变量word的可访问性会受到怎样的影响?我该如何解决? 最佳答案 这将是模棱两可的,你会得到一个编译错误。您需要使用正确的范围来使用它:classDerived:publicA,publicB{Derived(){A::word="A!";B::word="B!!";}}; 关于c++-多重

c++ - 多重继承 : same variable name

classA{protected:stringword;};classB{protected:stringword;};classDerived:publicA,publicB{};在Derived中变量word的可访问性会受到怎样的影响?我该如何解决? 最佳答案 这将是模棱两可的,你会得到一个编译错误。您需要使用正确的范围来使用它:classDerived:publicA,publicB{Derived(){A::word="A!";B::word="B!!";}}; 关于c++-多重

C++14 警告 : too many template headers for variable (should be 0)

在尝试最近的g++-5编译器时,我在一个文件中写了以下语句:templateTa;templateinta=1;结果:warning:toomanytemplateheadersfora(shouldbe0)同样有效,它并没有真正专门化a.例如templateTa;templateinta=1;intmain(){std::cout这个语法有什么奥秘? 最佳答案 模板参数只能在function模板的显式特化中被省略。你有一个变量模板,所以你必须包含:templateinta=1;引用C++14(n4140),14.7.3/10(强调

C++14 警告 : too many template headers for variable (should be 0)

在尝试最近的g++-5编译器时,我在一个文件中写了以下语句:templateTa;templateinta=1;结果:warning:toomanytemplateheadersfora(shouldbe0)同样有效,它并没有真正专门化a.例如templateTa;templateinta=1;intmain(){std::cout这个语法有什么奥秘? 最佳答案 模板参数只能在function模板的显式特化中被省略。你有一个变量模板,所以你必须包含:templateinta=1;引用C++14(n4140),14.7.3/10(强调

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++指南之一的误解。该指南说更喜欢初始化而不是赋值,但在您的示例中