草庐IT

typedeffing

全部标签

c++ - 用 typedef 重载会报错

考虑以下类型:#includetypedefunsignedlonglongusize_t;typedefunsigned__int16uword_t;typedefuword_tclockval_t;//timewithoutsecondsinformatHHMMstd::stringtoString(clockval_tnClock){returnstd::to_string((usize_t)nClock/100)+":"+std::to_string((usize_t)nClock%100);}std::stringtoString(uword_tnValue){returns

c++ - 是否有 high_resolution_clock 不是 typedef 的标准库实现?

20.12.7.3的C++草案内容如下:high_resolution_clockmaybeasynonymforsystem_clockorsteady_clock当然这可能没有强制要求,但我想知道:high_resolution_clock对于typedef以外的东西有什么意义吗?有这样的实现吗?如果设计出一个滴答周期较短的时钟,它可以是稳定的也可以是不稳定的。因此,如果存在这样的机制,我们是否也想“改进”system_clock和high_resolution_clock,再次默认为typedef解决方案? 最佳答案 规范之所

c++ - 使用来自元函数的 typedef 声明成员函数

考虑以下代码:templatestructFoo_s{usingtype=void();};templateusingFoo_u=void();templatestructBar{Foo_ufoo1;//OKtypenameFoo_s::typefoo2;//OKFoo_ufoo3;//OKtypenameFoo_s::typefoo4;//Boom.};templatestructBar;foo4的声明在GCC7.2、Clang5.0.0和MSVC19.10.25017上失败。海湾合作委员会::Ininstantiationof'structBar':18::18:17:requir

c++ - 为什么当一个模板类继承另一个模板类时,需要重新指定typedefs和函数调用限定?

当一个模板类继承另一个模板类时,基类中的typedef必须重新定义(即不会自动继承),基类中的函数调用需要限定。这是为什么?这不是已经很明确了吗?因此,如果我有20个模板类,都定义了相同的typedef,我将无法引入包含这些定义的基类并从中继承,因为无论如何我都必须在每个类中重新定义typedef,这会破坏目的。这使得源代码变得不必要地冗长。我可以看到这已在question中讨论过,但我不明白评论TheC++namelookuprulesspecifythatanameisonlysearchedinatemplatedbaseclassesifitdependsonatemplate

c++ - 为什么 typedef 模板是非法的?

从实际的角度来看,我理解typedef和test都有些“多余”,如果我们要编译以下代码,则需要将其删除:templatetypedefstructtagTest{inta;}test;但是,我认为typedef声明集是声明集的子集。他们只是碰巧有那个特定的decl-specifier。这是我的合理化typedefstructtagTest{inta;}test;引入标识符test并声明结构tagTest。如果该解释是正确的,那么标准中的以下段落应该允许templatetypedef(尽管不是关键字using给出的含义)>).Thedeclarationinatemplate-decla

c++ - typedef 和 using 会导致模板实例化吗?

假设我有一个这样定义的模板类templateclassTemp{//irrelevant};我可以隐式或显式实例化它:Tempti;templateclassTemp;通过显式实例化,我的程序应该包含一个实例,即使我以后不使用它(假设它没有被编译器优化省略)。我的问题是,下面的语句会导致类的实例化吗?typedefTempTShort;usingTFloat=Temp;//C++11 最佳答案 没有。Implicitinstantiation仅在需要完全定义的类型时才会发生;而类型别名则不必。Whencodereferstoatem

c++ - 是否可以在没有 typedef 的情况下声明返回数组引用的转换函数?

这是一个返回数组引用的转换函数:structS{typedefintint_array_20[20];operatorint_array_20&();};没有typedef是否可以做同样的事情?我试过的:structS{operatorint(&())[10];};但是clang提示:error:C++requiresatypespecifierforalldeclarationsoperatorint(&())[10];~^error:conversionfunctioncannothaveanyparametersoperatorint(&())[10];^error:mustus

C++ typedef 修复模板参数

从c++11开始,我们可以这样做:templateclassC{};templateusingD=C;所以D是C且B=int。有没有办法通过c++03中的typedef做到这一点?这不起作用:templatetypedefCD; 最佳答案 不可能这么简单。在C++03中唯一可以作为模板的是类和函数。关于类的好处是它们本身可以包含typedef作为成员(member)。templatestructD{typedefCtype;};所以现在D::type代表C.这就是模板元编程中所谓的元函数。它很好,因为您可以在C++03中实现它。虽然

c++ - "using"能否在所有情况下完全替换 "typedef"?

我知道using可以做typedef做不到的事情。我只是想知道使用是否可以在所有情况下完全替代typedef? 最佳答案 是的,引用自draftStandard(大胆强调我的)7.1.3typedef说明符[dcl.typedef]2Atypedef-namecanalsobeintroducedbyanalias-declaration.Theidentifierfollowingtheusingkeywordbecomesatypedef-nameandtheoptionalattribute-specifier-seqfollow

c++ - 为什么我不能在 Arduino 中传递 typedef 或 enum?

以下草图无法在Arduino环境中编译。鉴于typedefscanbeusedwithinArduinosoftware,AutomaticPrototypeGeneration是导致失败的底层机制吗?如果是,它是什么?为什么Arduino不提供围绕C++的轻量级包装器?#definePRODUCE_WACKY_COMPILETIME_ERRORtypedefintMyMeaningfulType;#ifndefPRODUCE_WACKY_COMPILETIME_ERRORvoidmyFunc(MyMeaningfulTypemyParam);#endifvoidmyFunc(MyMe