草庐IT

TYPE_SCROLL_SENSITIVE

全部标签

c++ - 如何在结构/类中获取有关 "current type"的信息?

是否有可能在struct中获取“当前struct的类型”?例如,我想做这样的事情:structfoobar{intx,y;booloperator==(constTHIS_TYPE&other)const/*WhatshouldIputhereinsteadofTHIS_TYPE?*/{returnx==other.x&&y==other.y;}}我试过这样做:structfoobar{intx,y;templatebooloperator==(constT&t)const{decltype(*this)&other=t;/*Wecanuse`this`here,sowecanget"

C++ 错误 : request for member '...' in 'grmanager' which is of non-class type 'GraphicsManager'

这个问题不太可能帮助任何future的访问者;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况有关,这些情况并不普遍适用于互联网的全局受众。为了帮助使这个问题更广泛地适用,visitthehelpcenter.关闭10年前。我的类GraphicsManager出现错误。图形管理器.cpp:#include"C:\Users\ChrisUzzolina\Desktop\obj\include\GraphicsManager.h"#include#includeGraphicsManager::GraphicsManager(intSCREEN_WIDTH,intSCREEN_

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++ - boost::lexical_cast<std::string>(Int_Type) 可以抛出吗?

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

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++ 从 ‘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