首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

typedef specifier

  • typedef-创建一个别名,该别名可用于任何位置,以代替%28(可能是复杂的%29类型名称)。

解释

typedef说明符,当在声明%27 s decl-说明符-seq,指定声明为类型胡枝子f声明,而不是函数或对象。它可以在同一行%28(G)上声明一个或多个标识符。INT和指向int%29的指针,它可以声明数组和函数类型、指针和引用、类类型等。在这个声明中引入的每个标识符都变成了ty胡枝子名称,这是如果关键字为关键字的对象或函数的类型的同义词。typedef被移除了。

typedef说明符不能与任何其他说明符组合,除非类型-说明符_s...

类型-名称是现有类型的别名,不是新类型的声明.。不能用于更改现有类型名称%28的含义,其中包括类型名称%29。一旦声明了,便只能重新声明tydurif名称以再次引用相同的类型。只有在可见的范围内,Ty对联名称才有效:不同的函数或类声明可以定义同名类型,其含义不同。

The typedef specifier may not appear in a declaration that does not contain a declarator. typedef struct X {}; // ill-formed

{{mark since c++17}}

关键词

typedef...

注记

类型别名使用不同的语法提供与Typedefs相同的功能,并且也适用于模板名称。

二次

代码语言:javascript
复制
// simple typedef
typedef unsigned long ulong;
 
// the following two objects have the same type
unsigned long l1;
ulong l2;
 
// more complicated typedef
typedef int int_t, *intp_t, (&fp)(int, ulong), arr_t[10];
 
// the following two objects have the same type
int a1[10];
arr_t a2;
 
// common C idiom to avoid having to write "struct S"
typedef struct {int a; int b;} S, *pS;
 
// the following two objects have the same type
pS ps1;
S* ps2;
 
// error: storage-class-specifier cannot appear in a typedef declaration
// typedef static unsigned int uint;
 
// typedef can be used anywhere in the decl-specifier-seq
long unsigned typedef int long ullong;
 
// std::add_const, like many other metafunctions, use member typedefs
template< class T>
struct add_const {
    typedef const T type;
};
 
typedef struct Node {
    struct listNode* next; // declares a new (incomplete) struct type named listNode
} listNode; // error: conflicts with the previously declared struct name

二次

另见

C.Ty对联f声明的文档

*。

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com