c++ - 是否允许重新定义类型名称?
问题描述
我有一个关于在类中重新定义类型名称的快速问题,C++ 中是否总是允许使用它,或者某些编译器会接受这个,其他编译器不会接受这种用法。
来自 C++ Premier 5th 第 7 章“类型名称是特殊的”部分的描述,下面是书中的代码片段。从它的评论中无法重新定义Money,这是否意味着不允许编译器重新定义类型名称?谢谢
/*copy from the book*/
typedef double Money;
class Account {
public:
Money balance() { return bal; } // uses Money from the outer scope
private:
typedef double Money; **// error: cannot redefine Money**
Money bal;
// ...
};
解决方案
推荐阅读
- flutter - SocketException:操作系统错误:连接被拒绝,errno = 111,地址 = localhost,端口 = 57838 #0
- java - ElasticSearchConfig 如何替换 NodeBuilder?
- android - How to combine columns from Android Room LEFT OUTER JOIN select statement
- openapi - OpenAPI 生成器没有为路径参数生成 @NotNull
- go - VSCode 在新的 GO 安装中找不到包
- python - 如何知道我的一个子弹精灵是否与我的敌人/巨石精灵相撞?- 游戏
- arrays - 比较 Ruby 中二维数组的子数组,并显示结果数组与现有和遗漏的项目
- css - CSS - 雪佛龙不会自行旋转
- javascript - javascript单行条件
- java - 在这种特定情况下,JPA Repository 给出从 Integer 到 Long 的强制转换异常的原因是什么?