对 self 的 typedef 有什么影响吗? [英] Does a typedef to self have any effect?

查看:54
本文介绍了对 self 的 typedef 有什么影响吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一些具有以下内容的 C++ 代码:

typedef 请求请求;

这只是一个空操作还是这个 typedef 实际有影响,如果有,它有什么影响?

解决方案

您可以在第 7.1.3 节中阅读与 C++2003 ANSI ISO IEC 14882 2003 的 typedef 说明符相关的所有规则.在 7.1.3 中,2) 已经说过,如果名称已经指代某种类型,则允许标识 typedef.

这是合法的:

typedef int 请求;typedef 请求请求;//重新定义请求"没有效果

事实并非如此:

typedef 请求请求;//非法,第一个请求"没有命名类型.

该标准有一个与此相关的具体示例.C++2003,第 7.1.3/2 节:

<块引用>

在给定的非类作用域中,可以使用 typedef 说明符重新定义在该范围引用它已经引用的类型.[示例:

typedef struct s {/* ... */} s;typedef int I;typedef int I;类型定义我我;

<块引用>

结束示例]

在 7.1.3 中,3) 曾说过禁止使用 typedef 将类型重新定义为另一个类型的别名

I've come across some C++ code that has the following:

typedef Request Request;

Is this just a no-op or does this typedef actual have an effect, and if so, what effect does it have?

解决方案

You can read all rules relative to typedef specifier for C++2003 ANSI ISO IEC 14882 2003 in section 7.1.3. In 7.1.3, 2) it have been said the identity typedef is allowed if the name already refers to some type.

This is legal:

typedef int Request;
typedef Request Request; // Redefines "Request" with no effect 

And that it is not:

typedef Request Request; // Illegal, first "Request" doesn't name a type. 

The standard has a specific example relating to this. C++2003, §7.1.3/2:

In a given non-class scope, a typedef specifier can be used to redefine the name of any type declared in that scope to refer to the type to which it already refers. [Example:

typedef struct s { /* ... */ } s;
typedef int I;
typedef int I;
typedef I I;

end example]

In 7.1.3, 3) it have been said that use typedef to redefine type to alias to another type is prohibited

这篇关于对 self 的 typedef 有什么影响吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆