草庐IT

intro_to_mapreduce

全部标签

C++ 标准 : return by copy to initialize a reference without RVO: is there any copy?

让我们考虑下一个示例:structbig_type{};//Returnbycopyautofactory(){returnbig_type{};}voidany_scope_or_function(){big_type&&lifetime_extended=factory();}假设RVO被禁止或根本不以任何方式存在,big_type()是否会或可以被复制?还是将引用直接绑定(bind)到return语句中构造的临时对象?我想确保big_type析构函数仅在any_scope_or_function结束时被调用一次。我使用C++14,以防某些行为在标准版本之间发生变化。

c++ - C/C++ : extract a subset of one enum to form a new enum

假设我有一个列出所有人员的主枚举:typedefenumall_personnel{//maleTONY,MIKE,JIM,//femaleJESSICA,MARY,}all_personnel_t;现在我想为male和female定义其他两个枚举(因为,例如,一些函数只接受males或females枚举参数),但我想使用与主枚举中相同的名称标识符。在C/C++中有可能吗?还是有其他方法?似乎以下内容不起作用(编译器提示redeclarationofenumerator‘TONY’等:typedefenummale_personnel{TONY,MIKE,JIM,}male_perso

c++ - 警告 C4244 : 'argument' : conversion from 'SIZE_T' to 'DWORD' , 可能丢失数据

我需要在我的代码中有一组重载函数,但我得到了转换wanrings。这是一个测试代码:#includewindows.hvoidf(DWORDarg){...}//voidf(SIZE_Targ){}voidmain(void){DWORDdword=0;SIZE_Tsize_t=dword;f(size_t);}编译器给出警告:test.cpp(11):warningC4244:'argument':conversionfrom'SIZE_T'to'DWORD',possiblelossofdata如果我取消注释voidf(SIZE_Targ)我得到test.cpp(5):errorC

c++ - C++ 代码错误 "expected constructor, destructor, or type conversion before ‘(’ token ”和 "no matching function for call to ..."

真正尝试解决错误,仔细检查所有内容。请帮忙。c++新手,请多关照。头文件(.h)#ifndefGUARD_Optimized_quick_sort_h#defineGUARD_Optimized_quick_sort_h#include#include#includeusingnamespacestd;templateclassoptimized_quick_sort{public:optimized_quick_sort(vectorarray){this->array=array;}optimized_quick_sort(listarray){vectortemp(array.b

c++ - 提升精神 : how to convert basic types?

假设我有一个std::string属性,但为了便于解析,我想使用qi::int_或qi::double_.是否有一种简单的方法可以将转换作为语义操作进行?我试过这样的:std::stringstreamss;my_int_as_str=qi::int_[ref(ss)但这甚至无法编译。编辑-尝试使用下面sehe的回答#include#include#include#includenamespaceqi=boost::spirit::qi;namespacephx=boost::phoenix;intmain(intargc,char*argv[]){std::stringtest="1

c++ - 无趣的模拟函数调用 bla() && 预期 : to be called at least once bla()?

我用模拟类编写了一个小测试。当我运行它时,首先我得到一个警告,说调用了一个无趣的模拟函数,然后测试失败,因为没有满足预期,即至少调用了一次模拟函数。有趣的是,当我看到上面的警告消息时,该函数被调用了。你对这件事有什么想法吗?谢谢!编辑:这是我的代码结构:classBla{public:Bla();virtual~Bla();virtualfloatmyFunction();}classMockBla:publicBla{MockBla();~MockBla();MOCKMETHOD0(myFunction,float());}classCallerClass{public:Caller

c++ - 错误 : expected primary-expression before ‘>’ : templated function that try to uses a template method of the class for which is templated

这个问题在这里已经有了答案:WhereandwhydoIhavetoputthe"template"and"typename"keywords?(8个答案)关闭8年前。在使用模板和仿函数(未出现在这个问题中)时,我最终遇到了以下简化的问题。以下代码(也可用here)classA{public:templateboolisGood(intin)const{constTf;returninbooltryEvaluator(T&evaluator,intvalue){returnevaluator.isGood(value);}intmain(intargc,constchar*argv[]

c++ - "Unable to start program"(调试版本)

MicrosoftVisualStudioUnabletostartprogram'theprogram.exe'.Thisapplicationhasfailedtostartbecausetheapplicationconfigurationisincorrect.Reviewthemanifestfileforpossibleerrors.Reinstallingtheapplicationmayfixthisproblem.Formoredetails,pleaseseetheapplicationeventlog.OK问题程序是一个C++项目,没有MFC,没有AFX,使用的库

C++ 精度 : String to Double

在对转换后的字符串执行一些操作后,我遇到了double的问题。#include#include#includeusingnamespacestd;//conversionfunctionvoidconvert(constchar*a,constinti,double&out){doubleval;istringstreamin(a);in>>val;cout并非所有以字符串形式输入的数字都是这种情况,因此错误不是恒定的。它只影响一些数字(34.38似乎是常数)。目前,当我传入a=34.38和i=100时,它会返回:chara--34.38Val-----34.38modifiedval

C++ Linux : error: ‘move’ is not a member of ‘std’ how to get around it?

所以在我的VS2010上我可以编译如下代码:boost::shared_ptrinternal_thread;boost::packaged_taskinternal_task_w(boost::bind(&thread_pool::internal_run,this,internal_thread));internal_thread=boost::shared_ptr(newboost::thread(std::move(internal_task_w)));前两行在boost1.47.0和linux上没问题...但是在std::move上它给出了error:‘move’isnota