草庐IT

char_type

全部标签

c++ - 从 std::true_type 继承 vs static constexpr const bool 成员

我知道这不是一个非常尖锐的问题。使用一个比另一个有优势(编译时间、依赖性、调试符号大小、可用性、可读性等)吗?templatestructIsSharedPtr:std::false_type{};对比templatestructIsSharedPtr{staticconstexprboolvalue=false;};相关问题...templatestructS;templatestructS{};templatestructS{};对比templatestructS;templatestructS{};templatestructS{}; 最佳答案

c++ - G++ 4.4.7 中的 "names the constructor, not the type"

我有以下简单的C++代码:#includeclassA{public:A(inty):x(y){}A&operator=(constA&rhs);intx;};A::A&A::operator=(constA&rhs){this->x=rhs.x;return*this;}intmain(int,char**){Aa1(5);Aa2(4);printf("a2.x==%d\n",a2.x);a2=a1;printf("a2.x==%d\n",a2.x);return0;}第11行,A的operator=()函数的定义所在,格式不正确......或者,至少,我相信是这样。正如预期的那样,

c++ - C++ 中的异常处理 Terminate 在抛出 'char const*' 的实例后调用

错误:抛出“charconst*”实例后调用终止终止应用程序已要求运行时以不寻常的方式终止它。请联系应用程序的支持团队。当我这样做时,我不确定是什么导致编译器崩溃。有任何想法吗?对编程有点陌生。#include#includeusingnamespacestd;//TemplateforMaximumtemplateXMaximum(Xarg1,Xarg2){if(arg1>arg2)returnarg1;elsereturnarg2;}//TemplateforMinimumtemplateMMinimum(Marg1,Marg2){if(arg1>arg2)returnarg2;e

c++ - 在函数中传递 char 数组?

这是我有问题的编码:我必须接受2个玩家的名字。然后,当播放器标记更改存储在“currentPlayer”中的名称的下一部分时,存储在playerOne或playerTwo中的名称也应更改。它没有,所以我该如何解决?请解决,我试图用&符号使它成为一个引用变量,但我收到一条错误消息,指出不允许引用数组。voidboardMarker(int&,charplayerOne[],charplayerTwo[],char&playerMarker,charcurrentPlayer[]);intmain(){charplayerOne[100];charplayerTwo[100];charcu

c++ - 前向声明的类型和 "non-class type as already been declared as a class type"

我对以下代码有疑问:templatevoidfoo(structbar&b);structbar{};intmain(){}它在GCC上编译成功,但在MSVC(2008)上编译失败并出现以下错误:C2990:“bar”:已声明为类类型的非类类型是代码错误还是MSVC中的错误?如果我在模板定义之前添加structbar;就可以了。 最佳答案 我们有我们的赢家:https://connect.microsoft.com/VisualStudio/feedback/details/668430/forward-declared-type-

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

我正在尝试对每个元素中包含一个int和一个字符串的vector进行排序。它是一个称为vector食谱的类类型的vector。出现上述错误,这是我的代码:在我的Recipe.h文件中structRecipe{public:stringget_cname()const{returnchef_name;}private:intrecipe_id;stringchef_name;在我的Menu.cpp文件中voidMenu::show()const{sort(recipes.begin(),recipes.end(),Sort_by_cname());}在我的Menu.h文件中#include

c++ - std::is_convertible 用于 type_info

在C++11中,可以通过usingstd::is_convertible确定类型A的变量是否可以隐式转换为类型B.如果你真的知道类型A和B,这很有效,但我只有type_infos。所以我正在寻找的是这样的功能:boolmyIsConvertible(consttype_info&from,consttype_info&to);是否可以在C++中实现类似的东西?如果是,怎么办? 最佳答案 在可移植的C++中做你想做的事是不可能的。可能如果您将自己限制在给定的平台上,则有可能获得部分答案。例如那些遵守ItaniumABI的平台将实现此功

c++ - 从 char 数组获取 int32_t 或 int64_t 值

我需要执行的操作要求我从char数组中获取一个int32_t值和2个int64_t值char数组的前4个字节包含int32值,接下来的8个字节包含第一个int64_t值,接下来的8个字节包含第二个。我不知道如何获得这些值。我试过了;int32_tfirstValue=(int32_t)charArray[0];int64_tfirstValue=(int64_t)charArray[1];int64_tfirstValue=(int64_t)charArray[3];int32_t*firstArray=reinterpet_cast(charArray);int32_tnum=fir

c++ - CRTP + 特征类 : "no type named..."

我尝试使用模板化类实现CRTP,但在使用以下示例代码时出现错误:#includetemplateclassTraits{public:typedeftypenameT::typetype;//'staticconstunsignedintm_const=T::m_const;staticconstunsignedintn_const=T::n_const;staticconstunsignedintsize_const=T::m_const*T::n_const;};templateclassCrtp{public:typedeftypenameTraits::typecrtp_typ

c++ - std::string 的 type_traits 段错误

从UsingSFINAEtocheckforglobaloperator收集信息和templates,decltypeandnon-classtypes,我得到了以下代码:http://ideone.com/sEQc87基本上,我将两个问题的代码结合起来,如果它有ostream声明,则调用print函数,否则调用to_string方法。摘自问题1namespacehas_insertion_operator_impl{typedefcharno;typedefcharyes[2];structany_t{templateany_t(Tconst&);};nooperatorstruct