草庐IT

Runtime-Type

全部标签

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++/LLVM : Runtime code generation and STL container

假设一个简单的部分评估场景:#include/*maybeknownatruntime*/intsomeConstant();/*canbepartiallyevaluated*/doublefoo(std::vectorargs){returnargs[someConstant()]*someConstant();}假设someConstant()是已知的并且在运行时不会改变(例如,由用户提供一次)并且可以被相应的int文字替换。如果foo是热路径的一部分,我预计会有显着的性能改进:/*partiallyevaluated,someConstant()==2*/doublefoo(s

c++ - 编译cuda文件报错: "runtime library" mismatch value 'MDd_DynamicDebug' doesn't match value 'MTd_StaticDebug' in vectorAddition_cuda. o

我尝试在Qt5.2和MSVC2012环境下编译一个cuda文件。在开始我的项目之前,我仔细阅读了问题并回复:CompilingCudacodeinQtCreatoronWindows.但是即使我简单地复制代码并在qt中生成2个文件,仍然会弹出一些错误/main.cpp/vectorAddition.cu错误是:errorLNK2038:mismatchdetectedfor'RuntimeLibrary':value'MDd_DynamicDebug'doesn'tmatchvalue'MTd_StaticDebug'invectorAddition_cuda.o我完全不知道如何修复这

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