On 12/11/2008, René Bürgel <[EMAIL PROTECTED]> wrote:
> If all members of the union are const, why don't you just make the union
> itself const?

The const for the union seems to be ignored (code below).  The
original reason behind the union shenanigans was to provide a
compile-time alias to another variable of the same type (due to fusion
of two large legacy code bases into one). It is of course possible to
provide an alias in the form of const int&, however I tried to avoid
the storage penalty.

struct my_class_3
  {
  const union
    {
    int x;
    int y;
    };

  my_class_3() : x(0) {}
  };

int main(int argc, char** argv)
  {
  my_class_3 abc;
  abc.y = 5;
  std::cout << abc.x << std::endl;
  return 0;
  }

output:
5

Reply via email to