DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: initializing a static array in a class

  1. #1
    Shayne Guest

    initializing a static array in a class


    I need to initilaize a static array of chars in my class, but my compiler
    keeps giving me errors. The code is as follows:

    class foobar{
    public:
    static char vars[2] = {'a','b'};
    };

    Any insight into why this won't work and how I might get around it would
    be greatly appreciated.

    Shayne

  2. #2
    Danny Kalev Guest

    Re: initializing a static array in a class

    you can't initialize an array within a class, even a static one. You can
    initialize it outside the class, at the place of its definition.

    int foobar:: vars[2] = {'a', 'b'};

    Danny
    Shayne wrote:
    >
    > I need to initilaize a static array of chars in my class, but my compiler
    > keeps giving me errors. The code is as follows:
    >
    > class foobar{
    > public:
    > static char vars[2] = {'a','b'};
    > };
    >
    > Any insight into why this won't work and how I might get around it would
    > be greatly appreciated.
    >
    > Shayne


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center