Topic: Is incomplete type definition allowed for enums ?


Author: appercel@ocegr.fr (Stephane Appercel)
Date: 1997/03/12
Raw View
I would like to know if incomplete type definition is allowed for enums.
Here is a program that does compile well on Visual C++ 4.2, but does
not on gcc (gnu compiler v2.7.2.1) or CC (sparcworks c++ compiler v4.1).

class Shape
{
public :
  enum T;
  virtual const T& Type() const = 0;
};

#define TYPE_RECTANGLE 0
#define TYPE_ELLIPSE 10

class Ellipse : public Shape
{
public :
  enum Shape::T
  {
    ELLIPSE = TYPE_ELLIPSE
   ,CIRCLE
  };
  virtual const T& Type() const;
private :
  T m_type;
};

const Shape::T& Ellipse::Type() const
{
  return m_type;
}

void f(const Shape& shape)
{
  switch (shape.Type())
  {
  case Ellipse::ELLIPSE :
    /* ... */
    break;
  case Ellipse::CIRCLE :
    /* ... */
    break;
  }
}

Thanks in advance
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson)
Date: 1997/03/12
Raw View
appercel@ocegr.fr (Stephane Appercel) writes:

>I would like to know if incomplete type definition is allowed for enums.

No, it is not.  You can't forward declare enums.
(Some compilers allow it as a non-standard extension, though.)

--
Fergus Henderson <fjh@cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3         |     -- the last words of T. S. Garp.
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]