943,708 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1936
  • C++ RSS
Nov 23rd, 2008
0

Class declaration syntax error

Expand Post »
C++ Syntax (Toggle Plain Text)
  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??
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Nickyu0712 is offline Offline
7 posts
since Nov 2008
Nov 23rd, 2008
0

Re: Class declaration syntax error

You are missing semicolon ; after your class' closing bracket and the assignment name = "Player"; should be strcpy(name, "Player");
Reputation Points: 134
Solved Threads: 18
Junior Poster
mrboolf is offline Offline
182 posts
since Jun 2008
Nov 24th, 2008
0

Re: Class declaration syntax error

now its even worse
C++ Syntax (Toggle Plain Text)
  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. }
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Nickyu0712 is offline Offline
7 posts
since Nov 2008
Nov 24th, 2008
0

Re: Class declaration syntax error

Semicolon is missing..
Example..
c++ Syntax (Toggle Plain Text)
  1. class Cmy
  2. {
  3. //...
  4. }; // here
Reputation Points: 47
Solved Threads: 69
Posting Whiz
cikara21 is offline Offline
340 posts
since Jul 2008
Nov 24th, 2008
0

Re: Class declaration syntax error

C++ Syntax (Toggle Plain Text)
  1. // what's this
  2. ITEM_atribut getAtribut();
Last edited by cikara21; Nov 24th, 2008 at 1:56 pm.
Reputation Points: 47
Solved Threads: 69
Posting Whiz
cikara21 is offline Offline
340 posts
since Jul 2008
Nov 24th, 2008
0

Re: Class declaration syntax error

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.
Reputation Points: 134
Solved Threads: 18
Junior Poster
mrboolf is offline Offline
182 posts
since Jun 2008
Nov 24th, 2008
0

Re: Class declaration syntax error

I see a very bad class design and implementation but no any compile-time errors ...
Reputation Points: 1234
Solved Threads: 347
Postaholic
ArkM is offline Offline
2,001 posts
since Jul 2008
Nov 25th, 2008
0

Re: Class declaration syntax error

Click to Expand / Collapse  Quote originally posted by mrboolf ...
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Nickyu0712 is offline Offline
7 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: char variables
Next Thread in C++ Forum Timeline: Detect a specific frequency tone





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC