0

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

2
Contributors
2
Replies
3
Views
11 Years
Discussion Span
Last Post by denn0069
0

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
0

Thanks, :cheesy:
thought that with statics it was permissable though.

cheers,
denn0069

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.