草庐IT

size_type

全部标签

用于负数组索引的 C++ size_t 和 ptrdiff_t

我很难在size_t之间做出选择和ptrdiff_t对于索引的类型,应该需要能够存储负值。准确地说,在我的代码中我需要实现一个数组。我收到它的长度(在构造函数中)作为size_t的类型,当我重载[]operator我需要索引的类型为ptrdiff_t(而不是size_t),因为我想允许负索引,如本例所示:std::size_tlength=50;MyVectorvec(length);vec[0]=10;MyVectorvec2=vec+1;std::cout上述设计引起的问题是可用索引的范围受限于ptrdiff_t的最大值。,在某些机器上,这个上限小于size_t的最大值。即std:

c++ - boost::lexical_cast<std::string>(Int_Type) 可以抛出吗?

有没有可能boost::lexical_cast(Int_Type)扔?我唯一能想到的是字符串没有内存的地方,但是还有其他更合理的选择吗? 最佳答案 根据documentation,lexical_cast可以扔bad_lexical_cast.最重要的是,正如您已经提到的,可能存在动态分配,它总是会导致bad_alloc异常。编辑:至于具体情况lexical_cast,除了分配错误之外,链上的任何部分似乎都不太可能失败,但文档并不(据我所知)保证不会出现“错误转换”异常。 关于c++-

微信小程序上传时报错message:Error: 系统错误,错误码:80051,source size 2148KB exceed max limit 2MB

问题:微信小程序上传时错误码:80051,sourcesize2248KBexceedmaxlimit2MB问题原因:由于代码中的静态资源图片大小超了200k以及主包的体积超出1.5M解决办法分包tabBar是主包的,不需要分包处理,以下是分包示例项目目录如下首先将login,register、和webview进行分包,通过引入路由的方式进行分包处理router代码如下//router/index.tsconstwebview=require("./webview");constregister=require("./register");constlogin=require("./login

C++11 : unique_ptr complains about incomplete type, 但是当我包装它时不是

SO上已经有很多关于unique_ptr和不完整类型的问题,但没有一个能给我一个概念来理解为什么以下内容不起作用://error:...std::pair::secondhasincompletetypetemplatestructImpl{typedeftypenamestd::unordered_map>::iteratoriter_type;std::unique_ptrptr;Impl():ptr(newiter_type()){}};intmain(){Impl();return0;}而以下是:templatestructImpl{structWrapper{typedeft

c++ - Type t = Type() 是否调用复制构造函数?

我真的很困惑....Typet=Type()是否调用复制构造函数?我问是因为当我尝试时:#includeclassTest{public:Test(Testconst&){std::cout什么都没有输出,但是当我把它改成#includeclassTest{Test(Testconst&){std::cout我得到:errorC2248:'Test::Test':cannotaccessprivatememberdeclaredinclass'Test'这没有意义(特别是因为这是一个调试版本)。更新:即使这样也可以编译!structTest{Test(Test&&)=delete;Te

c++ - GCC 7,aligned_storage 和 "dereferencing type-punned pointer will break strict-aliasing rules"

我编写的代码在GCC4.9、GCC5和GCC6中没有警告。它在一些较旧的GCC7实验快照(例如7-20170409)中也没有警告。但在最近的快照(包括第一个RC)中,它开始产生关于别名的警告。代码基本上可以归结为:#includestd::aligned_storage::typestorage;intmain(){*reinterpret_cast(&storage)=42;}使用最新的GCC7RC编译:$g++-Wall-O2-cmain.cppmain.cpp:Infunction'intmain()':main.cpp:7:34:warning:dereferencingtyp

c++ - 设计建议——返回子类时避免 "invalid covariant return type"

我有以下情况:我指定一个纯虚函数:虚拟PredictedMatchPredictMatch(constMatch&match)const=0;我还有:类ImpactPredictedMatch:publicPredictedMatch现在,我想做的是:ImpactPredictedMatchPredictMatch(constMatch&match)const;在一个实现了之前的纯虚函数的类中。我原以为编译器会根据需要简单地转换返回的类型,但我得到:impact_predictor.h:18:24:错误:“虚拟ImpactPredictedMatchImpactPredictor::P

c++ - 错误 : argument of type char* is incompatible with parameter of type LPCWSTR

#include#includeusingnamespacestd;intmain(){char*file="d:/tester";WIN32_FIND_DATAFindFileData;HANDLEhFind;hFind=FindFirstFile(file,&FindFileData);//lineoferrorsaysargumentoftypechar*isincompatiblewithparameteroftypeLPCWSTR}我无法理解错误。错误是什么以及如何解决错误?我正在制作一个控制台应用程序,需要检查目录中是否有文件。 最佳答案

C++ "new T[size]"不起作用?

我有一个模板类定义为:#include#includeusingnamespacestd;templateclasstbufferpool{private:constintm_initial;constintm_size;constintm_total;T*m_buffer;vectorm_queue;public://constructortbufferpool(intinitial,intsize):m_initial(initial),m_size(size),m_total(initial*size){m_buffer=newT[m_total];T*next_buffer=m

c++ - boost .python : Argument types did not match C++ signature

我在python中调用C++函数时遇到一个奇怪的问题。我公开了一个我想从中调用函数的类:class_>("MyClass",init())//....def("someFunc",&MyClass::someFunc);我得到一个std::shared_ptr来自另一个类的成员变量,该类通过.def_readonly(...)公开当我尝试调用该函数时,出现以下错误:File"pytest.py",line27,intest_funccu.someFunc("string")Boost.Python.ArgumentError:PythonargumenttypesinMyClass.s