草庐IT

set_allocated

全部标签

c++ - 带有 std::set 的删除删除习语失败并出现与 constness 相关的错误

这个问题在这里已经有了答案:Deletingelementsfromstd::setwhileiterating(8个回答)关闭3年前。有人可以帮我吗?编译这段代码:voidtest(){std::settest;test.insert(42);test.erase(std::remove(test.begin(),test.end(),30),test.end());//编译时出现如下错误:$makeg++-c-Wall-pedantic-errors-Wextra-Wunused-Werrora_star.cpp/usr/lib/gcc/i686-pc-cygwin/4.3.4/i

c++ - std::promise set_value 和线程安全

我对std::promise::set_value()上的线程安全要求有点困惑。standardsays:Effects:Atomicallystoresthevaluerinthesharedstateandmakesthatstateready但是,它也说promise::set_value()只能用于设置一次值。如果多次调用,则会抛出std::future_error。所以你只能设置一次Promise的值。事实上,std::promise的几乎每个教程、在线代码示例或实际用例都涉及2个线程之间的通信channel,其中一个线程调用std::future::get(),其他线程调用

c++ - std::promise set_value 和线程安全

我对std::promise::set_value()上的线程安全要求有点困惑。standardsays:Effects:Atomicallystoresthevaluerinthesharedstateandmakesthatstateready但是,它也说promise::set_value()只能用于设置一次值。如果多次调用,则会抛出std::future_error。所以你只能设置一次Promise的值。事实上,std::promise的几乎每个教程、在线代码示例或实际用例都涉及2个线程之间的通信channel,其中一个线程调用std::future::get(),其他线程调用

c++ - Visual Studio 2015 : is a set of const pointers allowed?

我们将很快升级到VS2015,我在重大更改列表中找到了这个:constelementsTheC++standardhasalwaysforbiddencontainersofconstelements(suchasvectororset).VisualC++2013andearlieracceptedsuchcontainers.Inthecurrentversion,suchcontainersfailtocompile.source我想知道是否有人知道这是否也适用于集合。我知道映射仍然可以包含const指针作为键,因为它们无论如何都是const。一个例子:std::set我还能这样

c++ - Visual Studio 2015 : is a set of const pointers allowed?

我们将很快升级到VS2015,我在重大更改列表中找到了这个:constelementsTheC++standardhasalwaysforbiddencontainersofconstelements(suchasvectororset).VisualC++2013andearlieracceptedsuchcontainers.Inthecurrentversion,suchcontainersfailtocompile.source我想知道是否有人知道这是否也适用于集合。我知道映射仍然可以包含const指针作为键,因为它们无论如何都是const。一个例子:std::set我还能这样

c++ vector.push_back 错误: request for member 'push_back' . ..,属于非类类型 'vector(char, allocator(char)) ()()'

我将Cygwin与GCC一起使用,最终我想将字rune件读入字符vector,并使用此代码#include#include#includeusingnamespacestd;intmain(intargc,char*argv[]){vectorstring1();string1.push_back('a');return0;}生成此编译时错误:main.cpp:Infunctionintmain(int,char**)':main.cpp:46:error:requestformemberpush_back'instring1',whichisofnon-classtypestd::v

c++ vector.push_back 错误: request for member 'push_back' . ..,属于非类类型 'vector(char, allocator(char)) ()()'

我将Cygwin与GCC一起使用,最终我想将字rune件读入字符vector,并使用此代码#include#include#includeusingnamespacestd;intmain(intargc,char*argv[]){vectorstring1();string1.push_back('a');return0;}生成此编译时错误:main.cpp:Infunctionintmain(int,char**)':main.cpp:46:error:requestformemberpush_back'instring1',whichisofnon-classtypestd::v

c++ - 如何在我自己的容器类中使用 std::allocator

我正在尝试编写一个使用STL分配器的容器类。我目前做的是拥有一个私有(private)成员(member)std::allocatoralloc_;(稍后将被模板化,以便用户可以选择不同的分配器)然后调用T*ptr=alloc_.allocate(1,0);获取指向新分配的“T”对象的指针(并使用alloc_.construct调用构造函数;请参阅下面的答案)。这适用于GNUC++库。但是,对于Solaris上的STLPort,这无法正确执行并导致各种奇怪的内存损坏错误。如果我改为这样做std::allocator_interface>alloc_;然后一切正常。使用STL::allo

c++ - 如何在我自己的容器类中使用 std::allocator

我正在尝试编写一个使用STL分配器的容器类。我目前做的是拥有一个私有(private)成员(member)std::allocatoralloc_;(稍后将被模板化,以便用户可以选择不同的分配器)然后调用T*ptr=alloc_.allocate(1,0);获取指向新分配的“T”对象的指针(并使用alloc_.construct调用构造函数;请参阅下面的答案)。这适用于GNUC++库。但是,对于Solaris上的STLPort,这无法正确执行并导致各种奇怪的内存损坏错误。如果我改为这样做std::allocator_interface>alloc_;然后一切正常。使用STL::allo

C++ 错误 : terminate called after throwing an instance of 'std::bad_alloc'

我在eclipse上使用下面的代码,我得到一个错误终止“在抛出'std::bad_alloc'what():std::bad_alloc的实例后调用”。我有RectInvoice类和Invoice类。classInvoice{public://......otherfunctions.....private:stringname;Matim;intwidth;intheight;vectorrectInvoiceVector;};我在Invoice的方法中使用下面的代码。//vect:vector*vect;RectInvoicerect(vect,im,x,y,w,h);this->