草庐IT

SEARCH_TYPE_DISPATCH

全部标签

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++ - 编译时分派(dispatch) : conditional on valid call

给定以下代码:templateclassJoinedObjectGroup:public_ObjectSpaceHolder,public_ObjectSpaceHolder{public:JoinedObjectGroup(GroupA&groupA,GroupB&groupB):_ObjectSpaceHolder(groupA),_ObjectSpaceHolder(groupB){}templateObjectTypeget(){//Dispatchtoappropriatehandler:onlyoneofthefollowingactuallycompilesas//eit

【C++】STL 算法 - 查找算法 ( 查找两个相邻重复元素 - adjacent_find 函数 | 有序容器中通过二分法查找指定元素 - binary_search 函数 )

文章目录一、查找两个相邻重复元素-adjacent_find函数1、函数原型分析2、代码示例二、有序容器中通过二分法查找指定元素-binary_search函数1、函数原型分析2、二分查找时间复杂度分析3、代码示例一、查找两个相邻重复元素-adjacent_find函数1、函数原型分析在C++语言的标准模板库(STL,STLStandardTemplateLibrary)中,提供了adjacent_find算法函数用于在容器中查找两个相邻的重复元素;如果找到两个相邻的重复元素,则返回指向这对元素的第一个元素的迭代器;如果没有找到两个相邻的重复元素,则返回指向序列末尾的迭代器;adjacent_

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++ 函数分派(dispatch)

我正在重构一个大类——我们称它为Big——它有大量的复制粘贴代码。大部分复制粘贴代码都存在于switchcase中,其中只有涉及的类型最终有所不同。代码根据类的enum成员变量进行切换,该类的值仅在运行时才知道。我试图解决这个问题涉及到有一个Dispatcher类,它通过一个名为lookup()的static函数查找适当类型的函数。执行实际工作的函数总是称为go()并且必须在包装类模板中定义(其唯一参数是当前正在打开的运行时enum值).go()函数本身可能是也可能不是模板函数。这是代码的精简版。对于篇幅,我深表歉意,但这是我在不丢失重要上下文的情况下所能做到的最短。#includec

C++ 从 ‘const type* const’ 到 ‘type*’ 的无效转换

我有一个非常愚蠢的问题(我认为)。很长时间没有用C++编码,但我无法弄清楚这个问题。我有这个类:#includeclassNode{private:QList_adjacent;public:Node();boolisConnectedTo(Node*n)const;};isConnectedTo()的实现:boolNode::isConnectedTo(Node*n)const{return_adjacent.contains(n)&&n->_adjacent.contains(this);}我在return行中收到以下错误:Node.cpp:Inmemberfunction‘con

c++ - typedef type * type::* ,它是什么?

我有以下代码:structmyType{myType*ptr;};typedefmyType*myType::*other_type;第二行typedef'ining是什么?这是一个返回myType指针或其他东西的成员函数吗? 最佳答案 将other_type定义为指向myType成员的指针,其中所述成员本身是指向myType的指针。例如,您可以这样使用它:other_typex=&myType::ptr;myTypemine;mine.*x=&mine;为什么你会这样做,我不能说。 关