草庐IT

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++ - 这是 Solaris Studio 中的一个错误吗?

源代码(在问题的末尾)将引发我认为是SolarisStudio(而不是其他编译器)上的错误处理。为清楚起见,错误消息已重新格式化为新行:"overload.cpp",line44:Error:runGenEntries>(constGenEntryRuleDriven&,conststd::vector&)andrunGenEntries>(constGenEntryRulesDriven&,conststd::vector&)havesameexternname"__1cNrunGenEntries4nDstdGvector4Cin0AJallocator4Ci_____6FrkTA

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++ - SFINAE成员函数存在性测试问题

我有这个成员函数测试:templatestructhas_member{templatestatictrue_typef(decltype(declval().member())*);templatestaticfalse_typef(...);staticconstboolvalue=decltype(f(0))::value;};如果存在具有给定名称的成员函数,并且该函数具有不带参数的重载,则它的计算结果为true。对于此类函数以及在STL容器的情况下,它可以正常工作,但元素访问函数(前面、后面等)除外,在这些函数中它总是计算为false。这是为什么呢?我有mingwg++4.7。

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;为什么你会这样做,我不能说。 关

c++ - 返回所选类型的元组的类型函数

我已经实现了一个类型函数Tuple,它将My_enum值列表转换为相应类型的std::tuple:#includeenumMy_enum{t_int,t_double};//Bind_typeisatypefunctionthatgivenaMy_enumreturnsthecorrespondingtypetemplatestructBind_type;templatestructBind_type{usingtype=int;};templatestructBind_type{usingtype=double;};//Tupleisatypefunctionthatgivenate

c++ - 比较 typeid 指针

在这个程序中,我使用typeid来检查对象的派生类型:#include#include#include#include#includestructWrap{explicitWrap(int64_tid):mImpl(newImpl(id)){}explicitWrap(std::stringid):mImpl(newImpl(std::move(id))){}boolisInt64()const{constImplBase&impl=*mImpl;return(&typeid(impl)==&typeid(constImpl));}boolisString()const{constIm