草庐IT

strong_typedef

全部标签

c++ - 如何使 exuberant-ctags 解析 "using"样式的 typedef?

如何让ctags解析using类型别名,如下所示?usingFooPtr=std::shared_ptr;它只选取那些用typedef声明的。 最佳答案 从Exuberant-ctags派生的Universal-ctags(https://ctags.io)在C++源文件中处理“使用”:[jet@localhost]/tmp%cat/tmp/foo.cppusingFooPtr=std::shared_ptr;[jet@localhost]/tmp%u-ctags-o-/tmp/foo.cppFooPtr/tmp/foo.cpp/^

C++——typedef "inside"模板参数?

假设我有一个这样的模板函数:templatevoidmyfunc(Iteratora,typenameIterator::value_typeb){...}有没有办法通过为Iterator::valuetype声明一个typedef来实现同样的事情,我可以在函数签名中使用它?例如,我希望能够做这样的事情:templatevoidmyfunc(Iteratora,typeb){...}到目前为止,我已经求助于使用默认模板参数和Boost概念检查来确保始终使用默认值:templatevoidmyfunc(Iteratora,typeb){BOOST_STATIC_ASSERT((boost

c++ - 函数参数中的 Typedef 等价

如果没有例子,这个问题很难问,所以这里是:#includestructO{};structC{templatevoidfunction1(void(C::*callback)(constO*));templatevoidfunction2(void(C::*callback)(consttypenameT::value_type));voidprint(constO*);};intmain(){Cc;c.function1>(&C::print);//Success.c.function2>(&C::print);//Fail.}我得到的错误是:error:nomatchingfunc

c++ - 不同头文件中跨相同命名空间的 typedef

我目前正在学习C++并且正在努力编写一些代码:花园.h:#ifndefGARDEN_H_#defineGARDEN_H_#include#include#include"Shape.h"#include"Utils.h"namespacecma{typedefboost::shared_ptrShapePtr;typedefstd::vectorGardenPlan;}#endif/*GARDEN_H_*/实用程序.h:#ifndefUTILS_H_#defineUTILS_H_#include"Garden.h"namespacecma{voidprintList(GardenPla

c++ - 这是 typedef 结构的有效形式吗?如果是,它是什么意思?

现在正在处理一段代码,该代码具有以下形式的声明:typedefPACKED(struct){//somestuffinhere}struct_name;现在...PACKED是我们的宏。这个语法到底是什么意思?我不明白括号的用法。这不是编译,所以我猜这可能是不正确的。这是否接近其他一些有效语法,还是只是胡说八道?如果它几乎有效..实际上应该如何编写这段代码,它应该是什么意思?我见过并且可以在网上找到的typedef结构的唯一形式是:typedefstruct{//somestuffinhere}struct_name;已解决:我只需要意识到struct是宏函数中的一个参数。谢谢!

c++ - Typedef C++ 中的位域/掩码

我在C++中遇到这个问题:我可以typedef一个值来自枚举的位域吗?代码将更具解释性:typedef{AUDIO=0x01,VIDEO=0x02,SUBTITLE=0x04,DATA=0x08,GUARD,ALL=0xFF}my_enum_e;//I'dliketoreplace'unsignedint'by'my_enum_e'orsimilarintmyFunction(unsignedintmask){//code}//calledlikethis:myFunction(AUDIO|VIDEO|DATA);在函数的原型(prototype)中,我想使用my_enum_e作为输入

c++ - 没有模板重新绑定(bind)的 typedef 模板。作为模板类参数的模板使用

我想做这样的事情:templateclassBaseSubscriber{};templateclassBasePublisher{//notworking:invaliduseoftemplate-name'BaseSubscriber'withoutanargumentlisttypedefBaseSubscriberSubscriberType;//compilingtypedefBaseSubscriberSubscriberTypeT;};templateclassSubscriber,classData>classClassA:publicSubscriber{};temp

c++ - 混合 typedef 和 CRTP?

考虑以下示例:#include#include#includetemplateclassCrtp>classBase{public:typedefintvalue;//f1:OK//Expectedresult:casts4.2toBase::valuevaluef1(){return4.2;}//f2:NOTOK//Expectedresult:casts4.2toCrtp::value//Butf2doesnotcompile:notypenamed'value'//in'classDerived'typenameCrtp::valuef2(){return4.2;}};templ

c++ - 详细类型指的是 Clang 上的 typedef 错误

我在使用此编译器AppleLLVM版本5.1(clang-503.0.40)时遇到以下错误代码在这里测试.hclassmedia{public:typedefenum{audio,video,text,data}mediatype;};测试.cpp#include"test.h"intmain(){enummedia::mediatypemedias[]={media::audio,media::video};for(inti=0;(itest.cpp:5:15:错误:详细类型指的是typedef枚举media::mediatypemedias[]={media::audio,medi

c++ - 在 C++ 中使用 const ArrayType 或 ConstArrayType typedef 具有 const 元素的数组

我将定义一些具有固定大小和常量元素的数组。我尝试使用typedef,但似乎有些困惑:typedefintA[4];typedefconstintCA[4];constAa={1,2,3,4};CAca={1,2,3,4};a[0]=0;ca[0]=0;a=ca;ca=a;所有赋值都会导致上面代码中的语法错误,我认为a[0]=0;在我测试之前应该是合法的。考虑指针,结果更容易理解p[0]=0;和cp=p;是正确的。typedefint*P;typedefconstint*CP;constPp=newint[4]{1,2,3,4};CPcp=newint[4]{1,2,3,4};p[0]=