草庐IT

St9bad_alloc

全部标签

c++ - 标准 select1st 和 select2nd

在C++11中是否有任何标准的select1st和select2st等价物?这些似乎只在GNUCPP中定义过. 最佳答案 对于get定义的所有事物:templateconstexprautoselect=[](auto&&x)noexcept->decltype(auto){returnstd::get(std::forward(x));}; 关于c++-标准select1st和select2nd,我们在StackOverflow上找到一个类似的问题: htt

C++ API 设计 : is using void* a bad idea?

我正在开发一个我希望在调用方尽可能通用的API。主要设计思想是提供一种信号/插槽类型的实现,允许API的用户订阅一组给定的事件,并将用户定义的回调附加到它们。公共(public)界面看起来像这样:RetCallbacksubscribe(EventEnum&ev,std::functionfn)const;:注意void(void*)在这里签名。EventEnum在公共(public)头文件中给出,以及类型定义。然后,API的内部工作将通过通知方法将事件通知其订阅的观察者,并提供要转发给客户端的数据:voiddummyHeavyOperation()const{std::this_th

c++ - OpenCV SVM 在火车上抛出异常, "Bad argument (There is only a single class)"

我卡在这个了。我正在尝试通过OpenCV特征2d框架进行一些对象分类,但在训练我的SVM时遇到了麻烦。我能够提取词汇表并使用BowKMeansTrainer对它们进行聚类,但在我从训练数据中提取特征以添加到训练器并运行SVM.train方法后,出现以下异常。OpenCVError:Badargument(Thereisonlyasingleclass)incvPreprocessCategoricalResponses,file/home/tbu/prog/OpenCV-2.4.2/modules/ml/src/inner_functions.cpp,line729terminatec

c++ - bad_alloc 在初始化和填充 vector 时?

在尝试生成随机数vector时,我偶然发现了一个std::bad_alloc错误。这是我的代码:#include"search.h"#include"gtest/gtest.h"int_size=100;std::vectorGetSortedVector(intsize){//initvectorstd::vectorv(size);//fillwithrandomnumbersfor(std::vector::size_typei=0;iv=GetSortedVector(_size);//nothingmovesfartherthanthisline}附注:我现在确实在使用gen

c++ - OpenCV 2.4.2 错误 "OpenCV Error: Bad flag"

我刚开始尝试使用OpenCV,并且根据一本书编写了一个非常简单的小程序。问题是当我尝试编译它时,出现此错误。我会告诉你我所有的信息。我使用Homebrew软件为MacOSX10.7安装了openCV。#include#includeintmain(intargc,char*argv[]){cv::Matimage=cv::imread("usf.gif");cv::namedWindow("MyImage");cv::imshow("MyImage",image);cv::waitKey(5000);return1;}我喜欢这样编译:g++-otestopencvtest.cc-lop

c++ - 尽管未定义 <new> header ,但 New 会抛出 bad_alloc?

new是怎么回事?程序中的表达式可以抛出bad_alloc尽管没有#include还是出错(因为这个错误isdefinedintheheader)?来自3.7.4。N3337的:Thelibraryprovidesdefaultdefinitionsfortheglobalallocationanddeallocationfunctions.Someglobalallocationanddeallocationfunctionsarereplaceable(18.6.1).AC++programshallprovideatmostonedefinitionofareplaceablea

c++ - 为什么STL要为Allocator预留接口(interface)?

STL为什么要为Allocator预留接口(interface)?以vector为例:template>classvector;因为我们有很多选择来分配内存和构造对象,比如operatornew,delete,new[],delete[],它几乎可以做我们创建对象时需要做的任何事情。那么,为什么像vector这样的STL容器需要一个Allocator接口(interface),如果我们不分配一个,它在大多数情况下都是默认的std::allocator?为什么不直接使用新的表达式呢?如果目的是使用户定义的分配行为成为可能,为什么不让用户提供他们自己定义的operatornew、new[]

c++ - 使用 bind1st 还是 bind2nd?

vectorvwInts;vectorvwIntsB;for(inti=0;i(),5));//methodonetransform(vwInts.begin(),vwInts.end(),inserter(vwIntsB,vwIntsB.begin()),bind2nd(plus(),5));//methodtwo我知道bind1st和bind2nd之间的用法差异,方法一和方法二都为我提供了预期的结果。在这种情况下(即转换的使用)真的没有太大区别所以我可以使用bind1st或bind2nd吗?因为,到目前为止我看到的所有示例都使用方法二。我想知道上述情况下的bind1st和bind2

c++ - 为什么 `e.what()` 打印 "bad allocation"?

tryblock中的new表达式在我的计算机中引发了bad_alloc异常。请注意,catch子句按值而不是按引用接收异常对象。为什么e.what()会打印出"badallocation"?我以为它会被切成薄片。#includeintmain(){try{int*p=newint[0x1F000000];}catch(std::exceptione){std::cout 最佳答案 VisualStudio(Dinkumware?)使用std::exception的实现,其中包含消息的内部存储†。(完成一个接受字符串的非标准构造函数。

c++ - 在抛出 'std::bad_alloc' what(): std::bad_alloc 的实例后终止调用

我的程序中出现了bad_alloc异常。这些是限制条件:1每个字符串的长度最多为100000,并且只包含小写字符。由于这些限制,我无法弄清楚为什么我的程序得到bad_alloc。#include#include#include#includeclassSuffixArray{std::vectorsuffixes;size_tN;public:SuffixArray(std::string&s){N=s.length();suffixes.resize(N);for(size_ti=0;i>T;std::vectorresults;for(inti=0;i>str;SuffixArra