Topic: Why does 9.4.2.4 only allow integrals and enumerations?


Author: jrwinter@mtu.edu (Jeffrey R. Winters)
Date: 1997/05/29
Raw View
Why does 9.4.2.4 only allow integrals and enumerations?

"4 If  a  static  data  member  is of const integral or const enumeration
  type, its declaration in the class definition can specify a  constant-
  initializer   which   shall   be   an   integral  constant  expression
  (_expr.const_).  In that case, the member can appear in integral  con-
  stant expressions within its scope.  The member shall still be defined
  in a namespace scope if it is used in the program  and  the  namespace
  scope definition shall not contain an initializer."

I can see some implementation difficulties with allowing ANY type but why
not const arrays of const integral or const enumeration types???


For example:

class X
{
    public:
        const int GetData()
        {
            return sData[mID];
        }

        //...

    private:
        static const int sData[] = { 1, 2, 3, 5, 7, 11 };

        unsigned int mID;
};

Why not const pointers (const :) ?

class Y
{
    public:
        const char* GetData()
        {
            return sData[mID];
        }

        //...

    private:
        static const char* const sData[] = { "Mon", "Tue", "Wed" };

        unsigned int mID;
};

Thanks,

Jeff
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]