[c++/visual studio 2003]Array Declaration Issue

Reply

Join Date: Nov 2006
Posts: 2
Reputation: denn0069 is an unknown quantity at this point 
Solved Threads: 0
denn0069 denn0069 is offline Offline
Newbie Poster

[c++/visual studio 2003]Array Declaration Issue

 
0
  #1
Nov 22nd, 2006
I have the following code:
  1. class date
  2. {
  3. private:
  4. unsigned int nDay,nMonth,nYear;
  5. static unsigned int nMonthArr[12] = {31,28,31,30,31,30,31,31,30,31,30,31}; //LINE 36
  6. ...
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
Last edited by denn0069; Nov 22nd, 2006 at 9:24 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,149
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1435
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: [c++/visual studio 2003]Array Declaration Issue

 
0
  #2
Nov 22nd, 2006
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.
  1. // *.h file
  2. class date
  3. {
  4. private:
  5. unsigned int nDay,nMonth,nYear;
  6. static unsigned int nMonthArr[12]; //LINE 36
  7. ...
  8.  
  9.  
  10. // *.cpp file
  11. unsigned int Date::nMonthArr[12] = {31,28,31,30,31,30,31,31,30,31,30,31}; //LINE 36
Last edited by Ancient Dragon; Nov 22nd, 2006 at 11:37 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 2
Reputation: denn0069 is an unknown quantity at this point 
Solved Threads: 0
denn0069 denn0069 is offline Offline
Newbie Poster

Re: [c++/visual studio 2003]Array Declaration Issue

 
0
  #3
Nov 23rd, 2006
Thanks, :cheesy:
thought that with statics it was permissable though.

cheers,
denn0069
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC