草庐IT

rows_to_zero

全部标签

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

c++ - 与 move 构造函数混淆 : unable to call move constructor

我一直难以理解C++中的move构造函数。我用默认构造函数、复制构造函数、move构造函数和析构函数制作了一个简单的类。此外,我定义了一个具有两个重载的函数,一个接受对该类的引用,一个接受对该类的右值引用。我的测试代码如下。#includeclassc{public:c(){std::cout我得到的输出不是我所期望的。以下是我从此代码获得的输出。defaultconstructorcopyconstructorpassedbyreferencedefaultconstructorpassedbyrvaluereferencedestructor除了第3行,我能理解所有行的输出。在第3

c++ - 奇怪的编译器错误 : "undefined reference to ' main'"

谁能告诉我这是什么意思?/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/../../../crt1.o:Infunction`_start':(.text+0x18):undefinedreferenceto`main'collect2:ldreturned1exitstatusmake:***[program]Error1我的make文件如下所示:program:main.orender.oscreenwriter.og++-omain.orender.oscreenwriter.o-lSDLmain.o:main.cpprender

c++ - C/C++ : Converting hexadecimal value in char to integer

我将十六进制值存储为字符:charA='0';charB='6';charC='E';...我需要将它们转换为整数。我知道'atoi',但这只适用于十进制编码的字符值。有类似的功能吗? 最佳答案 intv=(A>'9')?(A&~0x20)-'A'+10:(A-'0');对于ASCII是正确的。对于其他字符集,类似的方法也行得通,但您需要使用toupper而不是&~0x20。 关于c++-C/C++:Convertinghexadecimalvalueinchartointeger,我们

C++ 重载赋值运算符 : "cannot convert ` B *` to ` A *`" error

classB;classA{B*b;public:voidoperator=(B*b){this->b=b;}};B*b=newB()A*a=newA();a=b;我收到“无法将B*转换为A*”错误。有解决办法吗?现在,如果有办法,如果我使用类似的东西:a=NULL;将使用哪个运算符“=”? 最佳答案 您分配的是指针而不是对象。只需将最后一条指令替换为:*a=b;回答第二个问题:NULL可以在编译器中以多种方式定义(根据最新标准,作为整数0或文字nullptr)。指针也可以转换为其他类型的指针,但将void*传递给采用int*或lo

c++ - "error: no matching function for call to"

我当时在键盘上,我正在尝试使用C++来提高我的技能。我以前从未使用过模板,所以我尝试研究如何使用它们。下面的代码是结果,不幸的是,它不起作用。我确实尝试寻找问题的解决方案,但由于我没有太多使用模板的经验,所以我无法在我的问题和其他问题之间建立任何联系。所以,我决定寻求帮助。templateclassVector2{public:Ax,y;Vector2(Axp,Ayp){this->x=xp;this->y=yp;}};templateclassrayToCast{public:rayToCast(Bangle,Vector2origin,Vector2point1,Vector2po