草庐IT

type-equivalence

全部标签

C++ 错误 : Incompatible types in assignment of ‘char*’ to ‘char [2]

我的构造函数有点问题。在我的头文件中,我声明:charshort_name_[2];和其他变量在我的构造函数中:Territory(std::stringname,charshort_name[2],Player*owner,charunits);voidsetShortName(char*short_name);inlineconstchar(&getShortName()const)[2]{returnshort_name_;}在我的cpp文件中:Territory::Territory(std::stringname,charshort_name[2],Player*owner,

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

C++11 "enumerated types"(17.5.2.1.2)

引自C++11标准(17.5.2.1.2枚举类型):1SeveraltypesdefinedinClause27areenumeratedtypes.Eachenumeratedtypemaybeimplementedasanenumerationorasasynonymforanenumeration(Suchasanintegertype,withconstantintegervalues(3.9.1)).2Theenumeratedtypeenumeratedcanbewritten:enumenumerated{V0,V1,V2,V3,.....};staticconstenu

C++ 函数模板 : Derived and explicit return type

我有以下问题,我只是没有找到合适的解决方案(也许没有):我有一个模板化方法,其中返回类型取决于输入类型,感谢C++11decltype返回类型可以很容易地导出,但是如果需要,我还希望允许用户明确定义返回类型。更正式地说,我有一个模板化函数f,我想被调用为f(x),既没有显式定义输入类型,也没有显式定义返回类型。我也希望能够将其称为fx()明确定义返回类型,但输入类型仍然自动派生。现在,用C++11满足第一个约束很容易(假设还有另一个模板化方法:templateautof(constInT&in)->decltype(/*codederivingthereturntypeusingin*

c++ - type、value_type 和 element_type 之间有什么区别,何时使用它们?

我已经编写了一个模板类,它应该公开其模板参数,但我不确定合适的命名。我已经为本质上相同的东西找到了三个不同的名称(据我所知):容器,例如std::vector使用value_type智能指针,例如std::unique_ptr使用element_typestd::reference_wrapper仅使用type这些不同名称背后的想法是什么?哪些标准算法或特征类取决于哪个名称?我应该为我的类使用哪个名称(介于智能指针和引用包装器之间的名称)? 最佳答案 value_type是容器(以及迭代器等)的成员类型。它提供对象的类型,通常是一个