首页 > 解决方案 > 是否允许重新定义类型名称?

问题描述

我有一个关于在类中重新定义类型名称的快速问题,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;
    // ...
};

标签: c++redefine

解决方案


推荐阅读