dimanche 30 juin 2019

Typename redefinition inside class scope

This is the code

typedef double Money;

class Account {
public:
    Money balance() {
        return bal;
    }
private:
    typedef long Money;
    Money bal;
};

According to C++ Primer 5e, it is an error to redefine the same type (Money) in inner class scope.
However, it's also mentioned that some compilers may not enforce this.

Does that mean it is an undefined behavior, or unspecified behavior? If standard explicitly says that this is not allowed, how can major compilers decide not to flag this as an error?

Aucun commentaire:

Enregistrer un commentaire