草庐IT

void_type

全部标签

c++ - iterator_traits<InIter>::value_type 的创建是否会在传递时触发遵从? (异常测试)

我在故意为不特别遵守迭代器的函数抛出异常(出于测试目的)时遇到了麻烦。要了解我在做什么,请带上我的decorator_iterator结构:structdecorated_iterator:boost::iterator_adaptor,BaseIterator,boost::use_default,IteratorTag>{//....private:friendclassboost::iterator_core_access;/*usedtothrowanexceptionupondereference*/typenamebase_type::referencedereferenc

c++ - 具有推导的 void 返回类型的 Constexpr 类模板成员函数?

考虑以下简单类X和类模板Y每个定义四个constexpr成员,其中三个推导了它们的返回类型(新的C++1y特性),另外三个成员的另一个子集使用了另一个新的C++1y特性:轻松的constexpr现在也可以有副作用的函数和一个void返回类型。下面是这些功能交互的小实验:#include#includestructX{constexprvoidfun(){}//OKconstexprautogun(){}//OKautohun(){}//OKconstexprautoiun(){return0;}//OK};templatestructY{constexprvoidfun(){}//OK

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

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

c++ - 未解析的外部符号 boost::chrono::system_clock::now(void)

谷歌一直不友善...我最近取消了boost1.50,并尝试使用它来构建我的项目。这是一个大型项目,使用了多种boost功能(线程、信号、指针类、spirit等)。一些细节:-MSVC9.0(2008)-静态链接boost我在链接每个生成的exe时遇到错误,但是对于chrono,我没有直接链接它。错误是:libboost_thread-vc90-mt-sgd-1_50.lib(thread.obj):errorLNK2019:unresolvedexternalsymbol"public:staticclassboost::chrono::time_point>>__cdeclboost

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++ - eclipse c++ 中的 "control reaches end of non-void function"警告但没有编译或运行时错误

这是我的代码:Composer&Database::GetComposer(stringin_last_name){for(inti=0;i想法是遍历Composer对象数组并返回对其last_name字段与“in_last_name”匹配的对象的引用。我明白警告在告诉我什么,即函数可能不会返回任何内容(如果用户提供了无效的姓氏)。我的问题是,我怎样才能避免这种情况?我尝试在for循环之后添加“return0”和“returnNULL”,但它无法编译。如果此方法什么也没找到,是否应该抛出异常? 最佳答案 您的函数被声明为返回一个Co