Class declaration syntax error

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2008
Posts: 7
Reputation: Nickyu0712 is an unknown quantity at this point 
Solved Threads: 0
Nickyu0712 Nickyu0712 is offline Offline
Newbie Poster

Class declaration syntax error

 
0
  #1
Nov 23rd, 2008
  1. #include <string.h>
  2.  
  3. class ITEM //here i get the error
  4. {
  5. private:
  6. int price;
  7. char name[ 21 ];
  8. int efatr[ 4 ];
  9. public:
  10. void setName( char* newname );
  11. void setPrice( int newprice );
  12. void setAtribut( int x, int ef );
  13. ITEM()
  14. {
  15. name = "Player";
  16. price = 0;
  17. }
  18. ~ITEM();
  19. char* getName();
  20. int getPrice();
  21. ITEM_atribut getAtribut();
  22. }
  23.  
  24.  
  25.  
  26. void ITEM::setName( char* newname )
  27. {
  28. strcpy( name, newname );
  29. }
  30.  
  31. void ITEM::setPrice( int newprice )
  32. {
  33. price = newprice;
  34. }

i get a declaration syntax error at the class
Whats the problem??
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 182
Reputation: mrboolf will become famous soon enough mrboolf will become famous soon enough 
Solved Threads: 18
mrboolf mrboolf is offline Offline
Junior Poster

Re: Class declaration syntax error

 
0
  #2
Nov 23rd, 2008
You are missing semicolon ; after your class' closing bracket and the assignment name = "Player"; should be strcpy(name, "Player");
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 7
Reputation: Nickyu0712 is an unknown quantity at this point 
Solved Threads: 0
Nickyu0712 Nickyu0712 is offline Offline
Newbie Poster

Re: Class declaration syntax error

 
0
  #3
Nov 24th, 2008
now its even worse
  1. #include <string.h>
  2.  
  3.  
  4. class ITEM // declaration sytax error
  5. {
  6. private:
  7. int price;
  8. char name[ 21 ];
  9. int efatr[ 4 ];
  10. public:
  11. void setName( char* newname );
  12. void setPrice( int newprice );
  13. void setAtribut( int x, int ef );
  14. ITEM()
  15. {
  16. strcpy( name, "Player" );
  17. price = 0;
  18. }
  19. ~ITEM();
  20. char* getName();
  21. int getPrice();
  22. int getAtribut( int x );
  23. };
  24.  
  25.  
  26.  
  27. void ITEM::setName( char* newname ) // "declaration syntax errror " and "size of 'ITEM' is unknown or zero"
  28. {
  29. strcpy( name, newname );
  30. }
  31.  
  32. void ITEM::setPrice( int newprice )
  33. {
  34. price = newprice;
  35. }
  36.  
  37. char* ITEM::getName()
  38. {
  39. return name;
  40. }
  41.  
  42. int ITEM:: getPrice()
  43. {
  44. return price;
  45. }
  46.  
  47. int ITEM::getAtribut(int x)
  48. {
  49. return efatr[x];
  50. }
  51.  
  52. void ITEM::setAtribut( int x, int ef )
  53. {
  54. efatr[ x ] = ef;
  55. }
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 320
Reputation: cikara21 is an unknown quantity at this point 
Solved Threads: 63
cikara21's Avatar
cikara21 cikara21 is offline Offline
Posting Whiz

Re: Class declaration syntax error

 
0
  #4
Nov 24th, 2008
Semicolon is missing..
Example..
  1. class Cmy
  2. {
  3. //...
  4. }; // here
.:-cikara21-:.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 320
Reputation: cikara21 is an unknown quantity at this point 
Solved Threads: 63
cikara21's Avatar
cikara21 cikara21 is offline Offline
Posting Whiz

Re: Class declaration syntax error

 
0
  #5
Nov 24th, 2008
  1. // what's this
  2. ITEM_atribut getAtribut();
Last edited by cikara21; Nov 24th, 2008 at 1:56 pm.
.:-cikara21-:.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 182
Reputation: mrboolf will become famous soon enough mrboolf will become famous soon enough 
Solved Threads: 18
mrboolf mrboolf is offline Offline
Junior Poster

Re: Class declaration syntax error

 
0
  #6
Nov 24th, 2008
Post all the code you tried to compile, please. I can't see any error in this part.

Also, #include <string> , not string.h. And since you include it, why not use std::string name; ?
Last edited by mrboolf; Nov 24th, 2008 at 2:41 pm.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: Class declaration syntax error

 
0
  #7
Nov 24th, 2008
I see a very bad class design and implementation but no any compile-time errors ...
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 7
Reputation: Nickyu0712 is an unknown quantity at this point 
Solved Threads: 0
Nickyu0712 Nickyu0712 is offline Offline
Newbie Poster

Re: Class declaration syntax error

 
0
  #8
Nov 25th, 2008
Originally Posted by mrboolf View Post
Post all the code you tried to compile, please. I can't see any error in this part.

Also, #include <string> , not string.h. And since you include it, why not use std::string name; ?
im compiling it under an older complier, no std
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