草庐IT

Type_Ary

全部标签

c++ - "const T& operator[](size_type i)"中的 const 有什么用?

我在一本书http://www.acceleratedcpp.com/中发现了这个有趣的行-资源-第11章-Vec.h(我是一个std::vector翻版)而且我真的不明白这个版本的运算符有什么用。为什么要定义此运算符的两个版本(常量和非常量)?我什至试过了,在我看来,非常量版本一直被调用......你能解释一下吗?#include#include#include#includeusingnamespacestd;templateclassVec{public:typedefT*iterator;typedefconstT*const_iterator;typedefsize_tsiz

c++ - 错误 C2678 : binary '==' : no operator found which takes a left-hand operand of type (or there is no acceptable conversion)

我正在尝试编译以下代码:#include#include#includetypedefboost::geometry::model::d2::point_xyPoint;typedefstd::pairVector;booloperator==(constPoint&p1,constPoint&p2){returnp1.x()==p2.x()&&p1.y()==p2.y();}intmain(){Vectorvec1(Point(0,0),Point(1,1));Vectorvec2(Point(0,0),Point(1,2));std::coutVS2012C++编译器返回以下编译错

c++ - 海湾合作委员会 : Unscoped enumeration type give an ambiguity error

在下面的代码中,我定义了一个unscopedenumeration为longlong类型。该程序在Clang上运行良好。但是GCC编译器给出了一个歧义错误。#includeenum:longlong{Var=5};voidfun(longlongll){std::coutGCC产生的错误:main.cpp:Infunction'intmain()':main.cpp:17:12:error:callofoverloaded'fun()'isambiguousfun(Var);^main.cpp:5:6:note:candidate:voidfun(longlongint)voidfun

c++ - 自动返回类型扣除警告 : why do we need decltype when return defines the type anyway?

这是一个关于elementsSize()成员函数做什么的问题,关于自动返回类型推导:#include#includetemplateclassElementVector{std::vectorelementVec_;//Otherattributes.public:ElementVector()=default;ElementVector(conststd::initializer_list&list):elementVec_(list){}autoelementsSize()//->decltype(elementVec_size()){returnelementVec_.size(

c++ - Type** name 和 Type* name[] 有什么区别?

Type**name和Type*name[]有什么区别?为什么有人会使用一个而不是另一个?谢谢 最佳答案 这取决于它是在变量声明中还是在函数参数中?如果在变量声明中:Type**name=&pointer_to_type;Type*name[]={&pointer_to_type,0,&pointer_to_type};第一个是指向类型的指针,而第二个是指向长度为3的类型的指针数组。如果在函数参数中,它们是一样的。数组衰减为指针,Type**name和Type*name[]与函数参数完全相同。但是,第二种形式清楚地表明name是一个

c++ - 错误 : c++ [map] does not name a type

我编写了以下内容作为文本冒险游戏的文本命令解析器的一部分。我试图将用户输入的字符串与枚举类中的项目相关联。以下是我的头文件:#include#include#includeusingnamespacestd;enumclassNoun{//Interrogationsubjectsname,//askthesubjecthisnamebase,//whereisthebase?attack,//whenwilltheattackbe?invalid};mapknownNouns;knownNouns["name"]=Noun::name;knownNouns["base"]=Noun:

c++ - 函数/方法重载 C++ : Data type confusion?

我在C++中重载方法时遇到了一些问题。作为问题的一个例子,我有一个类,其中有许多方法被重载,并且每个方法都有一个具有不同数据类型的参数。我的问题:这些方法应该出现在类中是否有特定的顺序,以确保根据其参数数据类型调用正确的方法?classSomeClass{public:...voidMethod(boolparamater);voidMethod(std::stringparamater);voidMethod(uint64_tparamater);voidMethod(int64_tparamater);voidMethod(uint8_tparamater);voidMethod(

c++ - Clang 问题 : implicit type conversion at construction time

概要我正在努力使C++11代码与Clang兼容,并遇到了GCC>=4.6接受代码而Clang>=3.1不接受的情况。Clang认为候选构造函数不可行。详情这里是一个精简的例子来说明这个问题:#includetemplatestructT;templatestructT{typedefTsuper;constexprT(){}templateT(Args&&...){}};templatestructT:T{typedefTsuper;Headhead;T(Headarg):super(),head(std::move(arg)){}};structvoid_type{constexpr

c++ - std::type_info::hash_code() 的唯一性和 "should"的含义

是否意味着要保证相同的std::type_info::hash_code()值表示相同的类型?Cplusplus.com似乎是这么说的:Thisfunctionreturnsthesamevalueforanytwotype_infoobjectsthatcompareequal,anddifferentvaluesfordistincttypesthatdonot.[Emphasismine]Cppreference似乎另有说法:Returnsanunspecifiedvalue,whichisidenticalforobjects,referringtothesametype.No

c++ - 在 OSX 10.9.1 上使用 g++ 编译时出错 : unknown type name '__darwin_wctype_t'

在OSX10.9.1上使用g++从命令行编译基本代码(我附加了一个helloworld作为示例)时#includeintmain(){std::cout我用命令编译:g++hello.cc-ohw这会生成以下错误消息:Infileincludedfromhello.cc:1:Infileincludedfrom/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/iostream:38:Infileincludedfrom/Applicat