DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   [c++/visual studio 2003]Array Declaration Issue (http://www.daniweb.com/forums/thread62436.html)

denn0069 Nov 22nd, 2006 9:18 pm
[c++/visual studio 2003]Array Declaration Issue
 
I have the following code:
class date
{
private:
unsigned int nDay,nMonth,nYear;
static unsigned int nMonthArr[12] = {31,28,31,30,31,30,31,31,30,31,30,31}; //LINE 36
...
Upon compilation I recieve these errors:
n:\courses\8110\Labs\Lab7b\Lab7b.cpp(36) : error C2059: syntax error : '{'
n:\courses\8110\Labs\Lab7b\Lab7b.cpp(36) : error C2143: syntax error : missing ';' before '{'
n:\courses\8110\Labs\Lab7b\Lab7b.cpp(36) : error C2143: syntax error : missing ';' before '}'

I'm not sure what I am doing wrong here, I have only been working with c++ for a little while now and have searched everywhere to find nothing already posted on the web. Any help on this issue is greatly appreciated.

Denn0069

Ancient Dragon Nov 22nd, 2006 11:36 pm
Re: [c++/visual studio 2003]Array Declaration Issue
 
you can't initialize arrays like that in the class definitions. Initialize it in the *.cpp file just like you would any other global array.
// *.h file
class date
{
private:
unsigned int nDay,nMonth,nYear;
static unsigned int nMonthArr[12]; //LINE 36
...


// *.cpp file
unsigned int Date::nMonthArr[12] = {31,28,31,30,31,30,31,31,30,31,30,31}; //LINE 36

denn0069 Nov 23rd, 2006 12:40 am
Re: [c++/visual studio 2003]Array Declaration Issue
 
Thanks, :cheesy:
thought that with statics it was permissable though.

cheers,
denn0069


All times are GMT -4. The time now is 2:29 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC