草庐IT

clnt_call

全部标签

c++ - "If you' 已经写了一个编译测试,你've written a call to main"

在程序中调用mainviolatesC++标准voidf(){main();//anendlessloopcallingmain?Nothat'snotallowed}intmain(){staticint=0;std::cout在lecture中ChandlerCarruth,大约在“22.40”说ifyou'vewrittenacompilertestyou'vewrittenacalltomain这有什么关系,或者如何克服标准不允许的事实? 最佳答案 这里的要点是,如果你编写编译器测试代码,你可能会想用一些不同的参数集测试调用

c++ - 构造函数中抛出的异常 : is the destructor called?

这个问题在这里已经有了答案:Whatdestructorsarerunwhentheconstructorthrowsanexception?(3个答案)关闭8年前。如果在对象的构造函数中抛出异常,那么是否会调用析构函数?还是未定义的行为?(这就是为什么我不愿意说出我的编译器做了什么。)structfoo(){foo(){throw"bar";}~foo(){/*amIcalled*/}};foof;

c++ - 在 Visual Studio 中调用 std::swap 时的 std::bad_function_call

我正在尝试将我的代码从Linux移植到Windows。但是,对于VisualStudio,我的代码因以下错误而崩溃:MicrosoftC++exception:std::bad_function_callatmemorylocation这是我的代码:#includeclassFoo{public:Foo(int):m_deleter{[](){}}{}Foo(constFoo&)=delete;Foo(Foo&&)=default;Foo&operator=(constFoo&)=delete;Foo&operator=(Foo&&)=default;~Foo(){m_deleter(

c++ - 在 gmock 的 EXPECT_CALL 中调用 sleep()

我试图在调用FuncHelper之前在.WillOnce中做一些sleep。所以我需要类似于以下内容的内容:EXPECT_CALL(*_mock,Func(_,_,_)).Times(1).WillOnce(DoAll(InvokeWithoutArgs(sleep(TimeToSleep)),Invoke(_mock,&M_MyMock::FuncHelper)));是否可以在.DoAll中使用arg调用sleep()?C++98是首选。更新:该解决方案基于@Smeeheey的回答并使用C++98。templatevoidSleep(){sleep(N);}...EXPECT_CAL

C++ 模板和 "no matching function to call"

我遇到了一个奇怪的错误。我有以下签名的功能:templatestaticboolConvertCbYCrYToRGB(constCharacteristicspace,constDATA*input,DATA*output,constintpixels){后来这样称呼:casekByte:returnConvertCbYCrYToRGB(space,(constU8*)input,(U8*)output,pixels);casekWord:returnConvertCbYCrYToRGB(space,(constU16*)input,(U16*)output,pixels);casek

c++ - 谷歌模拟 : why NiceMock does not ignore unexpected calls?

我正在使用GoogleMock1.7.0和GoogleTest1.7.0。问题是当我使用NiceMock时,由于意外的模拟函数调用(根据GoogleMock文档,NiceMock应该忽略它)导致测试失败。代码如下所示://GoogleMocktest#include#includeusing::testing::Return;using::testing::_;classTestMock{public:TestMock(){ON_CALL(*this,command(_)).WillByDefault(Return("-ERRNotUnderstood\r\n"));ON_CALL(*

c++ - std::call_once 是免费的吗?

我想知道std::call_once锁是否空闲。There是使用互斥锁的call_once实现。但是我们为什么要使用互斥体呢?我尝试使用atomic_bool和CAS操作编写简单的实现。代码线程安全吗?#include#include#include#includeusingnamespacestd;usingmy_once_flag=atomic;voidmy_call_once(my_once_flag&flag,std::functionfoo){boolexpected=false;boolres=flag.compare_exchange_strong(expected,tr

c++ - std::call_once 和内存重新排序

给定来自here的代码:classlazy_init{mutablestd::once_flagflag;mutablestd::unique_ptrdata;voiddo_init()const{data.reset(newexpensive_data);}public:expensive_dataconst&get_data()const{std::call_once(flag,&lazy_init::do_init,this);return*data;}};我在其他地方也看到了相同模式的一些变体。所以我的问题是:为什么这段代码被认为是保存的?以及为什么编译器不能在调用std::c

c++ - std::runtime_error 子类的 "call to deleted constructor of"编译器错误

我从std::runtime_error派生了一个异常类,以便添加对异常流的支持。我收到一个奇怪的编译器错误输出,我不确定如何解决?clang++-std=c++11-stdlib=libc++-g-Wall-I../-I/usr/local/includeMain.cpp-cMain.cpp:43:19:error:calltodeletedconstructorof'EarthException'throwEarthException(__FILE__,__LINE__)^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~../EarthExce

c++ - 最烦人的解析 : why doesn't `g( ( f() ) );` call `f` 's default constructor and pass the result to `g` 's ctor that takes a `f` ?

这不是Mostvexingparse:whydoesn'tAa(());work?的拷贝,它基于Aa());形式的解析,其OP认为可以使用额外的集合默认构造一个A对象括号。相比之下,我的问题是关于2个类,f和g,其中f具有默认构造函数,而g的构造函数采用f。我想用一个临时的f参数调用g的构造函数,而不使用统一的初始化语法。g的构造函数中有一个std::cout语句,因此缺少输出表示函数声明而不是g对象实例化。我在注释中用3个数字注释了示例代码。#1和#2编译时#3被注释掉,反之亦然:#includestructf{};structg{g(f){std::cout#1:我认为#1声明了一