草庐IT

as-patterns

全部标签

c++ - MinGW: "gcc is not recognized as an internal or external command"

我下载并安装了MinGW。我使用图形程序安装C++编译器。在Windows命令行中键入gcc会打印:gccisnotrecognizedasaninternalorexternalcommand我检查了,gcc.exe存在于C:\MinGW\bin中。怎么了? 最佳答案 虽然是一个老问题,但这里的答案都没有帮助我。我发现到达目的地的唯一路线是在命令提示符下输入以下行:复制:设置Path=C:\MinGW\bin;%PATH%之后,只需输入gcc-v。希望这对解决我遇到的问题的人有所帮助!

c++ - 错误 : passing 'const …' as 'this' argument of '…' discards qualifiers

error:passing'constA'as'this'argumentof'voidA::hi()'discardsqualifiers[-fpermissive]我不明白为什么会出现这个错误,我没有返回任何东西,只是传递了对象的引用,就是这样。#includeclassA{public:voidhi(){std::cout@edit我使用const正确性修复了它,但现在我试图在同一个方法中调用方法,我得到了同样的错误,但奇怪的是我没有传递对这个方法的引用。#includeclassA{public:voidsayhi()const{hello();world();}voidhel

c++ - C++ 中的 "As a rule of thumb, make all your methods virtual"- 合理的建议?

我只是偶然看到了标题中的陈述。完整的报价是:Asaruleofthumb,makeallyourmethodsvirtual(includingthedestructor,butnotconstructors)toavoidproblemsassociatedwithomissionofthevirtualkeyword.我在Wrox的书ProfessionalC++中找到了这个。Youcangoogleittocheck.这有什么关系吗?我原以为您只会提供选择的扩展点,而不是默认的可扩展性。例如,a2001articlebyHerbSuttersaysso.从那以后,有什么发生了巨大

c++ - "cannot be used as a function error"

我正在编写一个使用不同.cpp文件中的函数的简单程序。我所有的原型(prototype)都包含在一个头文件中。我将一些函数传递给其他函数,但不确定我是否正确执行。我得到的错误是“'functionname'不能用作函数”。它说不能使用的函数是growthRate函数和estimatedPopulation函数。数据通过输入函数输入(我认为这是有效的)。谢谢!头文件:#ifndefheader_h#defineheader_h#include#include#includeusingnamespacestd;//prototypesvoidexterninput(int&,float&,

C++ 错误 - "member initializer expression list treated as compound expression"

我遇到了一个我不熟悉的C++编译器错误。可能是一个非常愚蠢的错误,但我不能完全指出它。错误:test.cpp:27:error:memberinitializerexpressionlisttreatedascompoundexpressiontest.cpp:27:warning:left-handoperandofcommahasnoeffecttest.cpp:27:error:invalidinitializationofreferenceoftype‘constBar&’fromexpressionoftype‘int’代码:1#include23classFoo{4publ

c++ - 为什么 as_const 禁止右值参数?

我想问为什么as_const禁止右值参数,accordingtocppreference.com(即为什么标准人员这样做,而不是为什么cppreference.com专门引用它们。而且也不是在哪里规范委员会的意图是编纂的,只是为了确保:)))。这个(人工)示例会产生错误(用户希望将其设为const以保持COW安静)QCharc=as_const(getQString())[0];Anotherquestion'sanswer指出,如果我们只是删除右值引用重载的删除,它会默默地将右值转换为左值。对,但为什么不优雅地处理右值,为右值输入返回constrvalues,为左值输入返回const

c++ - 如果不这样做,函数如何在新线程上运行 "as if"?

根据C++标准的[futures.async]/3项目符号1,当函数f使用std传递给std::async时::launch::async启动策略,f将“就像在新的执行线程中一样”运行。鉴于f可以做任何事情,包括无限循环和永远阻塞,实现如何提供f在其自己的线程上运行而不实际运行它的行为它自己的线程?也就是说,实现如何利用标准提供的“好像”摆动空间? 最佳答案 查看C++引用中出现的here和here,似乎“好像”的目标是让库实现者有一定程度的自由度。例如,它说asifspawnedbystd::thread(std::forward

c++ - 为什么 as_const 的 const&& 重载被删​​除了?

在blogontheprogressofC++17上我阅读了以下内容:P0007proposesahelperfunctiontemplateas_const,whichsimplytakesareferenceandreturnsitasareferencetoconst.templatestd::add_const_t&as_const(T&t){returnt}templatevoidas_const(Tconst&&)=delete;为什么要删除const&&重载? 最佳答案 考虑如果你没有重载会发生什么,并尝试传入一个co

c++ - 错误 : void value not ignored as it ought to be

templateZmyTemplate::popFromVector(){if(myVector.empty()==false)returnmyVector.pop_back();return0;}intmain(){myTemplateobj;std::cout错误:error:voidvaluenotignoredasitoughttobeAFAI可以看到,popFromVector的返回类型不是void。我错过了什么?当我在main()中注释掉这个调用时,错误消失了。 最佳答案 std::vector::pop_back()返

c++ - 错误消息 "undefined reference to template function passed as template parameter"

当我将模板函数作为基类的模板参数传递时,链接器提示它无法链接该函数:#includetemplateinlineintidentity(){returnI;}//templateinlineintidentity(){return20;}templateclassBase{public:intf(){returnfn();}};templateclassDerived:publicBase>{public:intf2(){returnf();}};intmain(intargc,char**argv){Derivedo;printf("result:%d\n",o.f2());retu