草庐IT

has_typedef_X

全部标签

c++ - 错误 : aggregate 'first one' has incomplete type and cannot be defined

我写了这个头文件(header1.h):#ifndefHEADER1_H#defineHEADER1_Hclassfirst;//intsumm(inta,intb);#endif和这个源文件(header1.cpp和main.cpp):#include#include"header1.h"usingnamespacestd;classfirst{public:inta,b,c;intsum(inta,intb);};intfirst::sum(inta,intb){returna+b;}#include#include"header1.h"usingnamespacestd;firs

c++ - 在实现文件中使用 typedef 来缩短类型签名的负面后果是什么?

我正在用C++做我的第一个真正的项目,它是一个简单的CSV解析器(目前处于非常早期的阶段),我在头文件中有以下内容:classCsvReader{public://ActionstocommitoneachiterationoftheCSVparserenumAction{ADD_CHAR,ADD_FIELD,NONE};//ThepossiblestatesforeachcellofaCSVenumState{START,IN_FIELD,IN_QUOTED_FIELD,IN_QUOTED_QUOTE};//CreatethereaderfromafileexplicitCsvRea

c++ - 转发声明 typedef 的结构

我不知道如何转发声明一个windows结构。定义是typedefstruct_CONTEXT{....}CONTEXT,*PCONTEXT我真的不想进入这个标题,因为它无处不在。我试过了结构语境和结构_CONTEXT运气不好(用winnt.h中的实际结构重新定义基本类型。 最佳答案 extern"C"{typedefstruct_CONTEXTCONTEXT,*PCONTEXT;}您需要声明_CONTEXT是一个struct。并将其声明为extern"C"以匹配windows.h的外部链接(这是一个C头文件)。但是,您不需要为typ

c++ - typedef 中的 const 警告

当我使用icc11编译C++程序时,它给出了这个警告:warning#21:typequalifiersaremeaninglessinthisdeclarationtypedefconstdirection_vector_ref_tdirection_vector_cref_t;它说const只是毫无意义。我对此很好奇,因为如果这个typedef展开它会变成constarray&和const绝对有意义。为什么会发出这个警告? 最佳答案 direction_vector_ref_t,我认为它是一个引用。引用在设计上是const的,因

c++ - 这个 has_member 类模板是如何工作的?

我试图了解以下类模板的工作原理(取自here),但我无法正确理解它:templateclasshas_member{classyes{charm;};classno{yesm[2];};structBaseMixin{voidoperator()(){}};structBase:publicType,publicBaseMixin{};templateclassHelper{};templatestaticnodeduce(U*,Helper*=0);staticyesdeduce(...);public:staticconstboolresult=sizeof(yes)==sizeo

c++ - 我可以使用类级别的 typedef 作为基类的模板参数吗?

假设一个模板化的基类:templateclassBaseClass;在其他类中,我想从中继承,其中T是一个相当复杂的类型,所以我想使用typedef。因为我不想污染命名空间,所以我希望在类定义中包含typedef:classChildClass:publicBaseClass{typedefMyVeryVeryComplicatedTypeLocalType;...}现在当然我还不能使用LocalType作为BaseClass的模板参数并且必须写两次复杂的定义(MyVeryVeryComplicatedType)。(所以我猜标题问题的答案是“否”。)问题:有没有办法只定义一次,但仍然只

c++ - 无法将 const 应用于 typedef 引用

以下代码在将const应用于value_type&的返回值引用时有效,但如果我使用相同类型的typedef,则会出错。举个例子:classT{};classA{public:typedefTvalue_type;typedefvalue_type&reference;//Notworkingconstreferenceoperator*()const;//Butthisworks?//constvalue_type&operator*()const;};//Error!consttypenameA::referenceA::operator*()const{}intmain(){ret

c++ - 警告 : second/third operand of conditional has no effect [-Wunused-value]

std::cout我想检查给定值是否可以创建三角形。我收到警告:secondoperandofconditionalexpressionhasnoeffect[-Wunused-value]thirdoperandofconditionalexpressionhasnoeffect[-Wunused-value]怎么了? 最佳答案 您的代码转换为:((std::cout首先,operator有更高的operatorprecedence比operator&&.只有abs(b-c)的值将被打印并且(a部分将与std::ostream::

c++ - 为什么 C++11 中没有模板化的 typedef?

这个问题在这里已经有了答案:WhydoesC++11nothavetemplatetypedef?(1个回答)关闭5年前。为什么委员会决定不批准模板化typedef和模板化using?templateusingmy_vector=std::vector;是合法的。但是templatetypedefstd::vectormy_vector;违法吗?更新。问题WhydoesC++11nothavetemplatetypedef?没有回答。

c++ - 可以在模板化的 typedef 上使用模板特化吗?

我想做类似下面的事情(在c++11、c++14中;而不是c++17):templateusingpartner=void;templateusingpartner=X;templateusingpartner=Y;templateusingpartner=Z;但是我得到一个编译错误---error:expectedunqualified-idbefore‘using’---关于第一个模板特化。这样的事情可能吗?(我已经知道我可以使用其中包含using语句的模板化类。我希望直接使用using语句而不使用类包装器,因为它更简单,更多优雅。如果有其他简单、优雅的解决方案,请分享!)