According to the book C++ Primer section, 7.4.1 Type Names Are Special:
Ordinarily, an inner scope can redefine a name from an outer scope even if tha
When the compiler reads the line
Money balance() { return bal; }
in the class definition, it already uses the definition of Money outside the class. That makes the line
typedef double Money;
inside the class a problem. However, you may use redefine Money inside the class before it is used in the class. The following is OK.
typedef double Money;
class Account {
public:
typedef double Money;
Money balance() { return bal; }
private:
Money bal;
};
The key point in the quote is:
hence the class may not subsequently redefine that name.