草庐IT

unique_no

全部标签

c++ - 为什么 Google Test/Mock 通过 std::unique_ptr 显示泄露的模拟对象错误?

假设有一个Bar对象,它使用了一个Foo对象。所有权是独占的,因此Bar在其构造函数中将Foo作为std::unique_ptr获取。我想用Google测试框架测试Bar,所以我编写了以下代码:usingnamespacetesting;classFoo{public:virtualintF()=0;};classBar{public:Bar(std::unique_ptr&&foo):m_foo(std::move(foo)){}intB(){returnm_foo->F();}private:std::unique_ptrm_foo;};classMockFoo:publicFoo

c++ - 在这种情况下 unique_ptr 的行为应该是什么?

假设我有以下内容:std::unique_ptrpA;pA(newA);在这个复杂的例子中,pA(newA);的行为应该是怎样的?是吗?据我所知,在MSVC2010中,voidoperator()(T*)const;在new之后立即调用fromdefault_delete立即返回并删除指针。而g++(4.7.0)给了我nomatchforcall(std::unique_ptr)(A*)错误。 最佳答案 代码不应编译。std::unique_ptr不会重载operator()。VisualC++2011DeveloperPrevie

c++ - 警告 C4180 : qualifier applied to function type has no meaning; ignored

我已经设置了编译器/Za选项来禁用语言扩展,以便编译器严格使用标准ISOC++。这是我收到以下警告的示例接口(interface)类warningC4180:qualifierappliedtofunctiontypehasnomeaning;ignored这是关于函数返回类型中的const限定符,如果我删除const,警告就会消失,但我不想这样做,我想重新启用lanqage扩展。我的问题是:这个警告合理吗?如果不是,那么我将使用pragma禁用警告,但在此之前我想确保此警告是“误报”因为下面的类是正确的ANSIISOC++不是吗?所以警告应该被禁用?classIBet{public:

c++ - std::unique_ptr<T> 不完整类型错误

我有templateclassqueue{private:structnode{Tdata;std::unique_ptrnext;//compileerroronincompletetypenode(T&&data_):data(std::move(data_)){}};std::unique_ptrhead;node*tail;public:queue():tail(nullptr){}我在VS10的标记行上遇到编译错误。在这种情况下,我是否应该被允许使用不完整的类型(实例化模板-构造函数-这里以int为例)?有解决方法吗?编辑singlethreadedqueue.h(62):e

c++ - 具有多态类型的 unique_ptr 未被删除

我有一个使用基类派生类型存储的unique_ptrvectorstd::unique_ptr>>decisionVariables;其中Variable是父类(superclass),派生类型是Route类。我的问题是,当包含decisionVariables的类被删除时,路由实例似乎没有被删除。路由来源于变量:#ifndef__VARIABLE__#define__VARIABLE__/***Interfacefordecisionvariables.*/#include#include#includeclassVariable{public:/***Returnsanindepen

c++ - "no ' operator++(int) ' declared for postfix '++ ' [-fpermissive]"枚举

这个问题在这里已经有了答案:HowcanIiterateoveranenum?(28个答案)Whycan'tIincrementavariableofanenumeratedtype?(10个答案)关闭9年前。我有枚举enumProgramID{A=0,B=1,C=2,MIN_PROGRAM_ID=A,MAX_PROGRAM_ID=C,}CurrentProgram;现在,我正尝试像这样递增CurrentProgram:CurrentProgram++,但编译器提示:没有为后缀'+声明'operator++(int)'+'[-fpermissive]。我认为有这样一个运算符可以增加“枚

c++ - make 给出错误 make : *** No rule to make target `clean' . Stop

您好,我有一个简单的MakeFile,其中包含:clean:rm-fex1但是当我运行命令makeclean时,出现以下错误:make:***Noruletomaketarget`clean'.Stop.我不确定我做错了什么,它只有2行,而第2行是以TAB而不是空格开头的。有人知道吗?我在MacOSX10.9.2上我实际上正在尝试学习c并遵循本教程:http://c.learncodethehardway.org/book/ex2.html 最佳答案 MakeFile应该命名为Makefile。去掉大写字母F。

c++ - 试图仅在 C++ 中模拟 Matlab "unique"函数

我有以下vector,v=[9295]及其唯一元素c=[259]按升序排列。我想提取vectoru=[3132]。uvector包含vectorc中唯一元素的索引,从而重构vectorv。我的想法是遍历v并借助基于c的唯一值构建的哈希表来获取索引值。这有意义吗?如果是的话,你能请一些人在c++中提出一种方法吗?高度赞赏其他建议(我对有效的实现感兴趣,因为v和c矩阵足够大)。最好的问候,托特 最佳答案 C++的索引是从0开始的,这样写比较正确u={2,0,2,1};您可以使用标准算法来完成任务。例如(这里我假设vectorc已经以某种

c++ - 错误 : no matching function for call to ‘to_string(std::basic_string<char>&)’

即使在模板中我可以有任何类型,函数to_string对基本字符串不起作用:例如:std::stringstr("mystring");my_class(str);用这个仿函数定义:templatevoidoperator()(valuetypevalue){...private_string_field=std::to_string(value);不起作用。这是错误:error:nomatchingfunctionforcallto‘to_string(std::basic_string&)’避免它的最佳方法是什么。事先,我要求避免仅仅因为一些常见的关键字就链接到不相关的问题。

c++ - "no matching function for call to ‘async(std::launch, <unresolved overloaded function type>, std::string&)’“

我正在尝试使用std::async创建线程,但我不断收到错误“没有匹配函数调用‘async(std::launch,,std::string&)’”在行上ConnectFuture=std::async(std::launch::async,Connect_T,ip);这是产生这种行为的代码:#includeclasslibWrapper{public:voidConnect(std::stringip);voidConnect_T(std::stringip);private:std::futureConnectFuture;};voidlibWrapper::Connect(std