RSS Forums RSS

Class declaration syntax error

Please support our C++ advertiser: Programming Forums
Reply
Posts: 4
Reputation: Nickyu0712 is an unknown quantity at this point 
Solved Threads: 0
Nickyu0712 Nickyu0712 is offline Offline
Newbie Poster

Class declaration syntax error

  #1  
Nov 23rd, 2008
#include <string.h>

class ITEM //here i get the error
{
	private:
		int price;
		char name[ 21 ];
		int efatr[ 4 ];
	public:
		void setName( char* newname );
		void setPrice( int newprice );
		void setAtribut( int x, int ef );
		ITEM()
		{
			name = "Player";
			price = 0;
		}
		~ITEM();
		char* getName();
		int getPrice();
		ITEM_atribut getAtribut();
}



void ITEM::setName( char* newname )
{
	strcpy( name, newname );
}

void ITEM::setPrice( int newprice )
{
	price = newprice;
}

i get a declaration syntax error at the class
Whats the problem??
AddThis Social Bookmark Button
Reply With Quote  
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

  #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  
Posts: 4
Reputation: Nickyu0712 is an unknown quantity at this point 
Solved Threads: 0
Nickyu0712 Nickyu0712 is offline Offline
Newbie Poster

Re: Class declaration syntax error

  #3  
Nov 24th, 2008
now its even worse
#include <string.h>


class ITEM // declaration sytax error
{
	private:
		int price;
		char name[ 21 ];
		int efatr[ 4 ];
	public:
		void setName( char* newname );
		void setPrice( int newprice );
		void setAtribut( int x, int ef );
		ITEM()
		{
			strcpy( name, "Player" );
			price = 0;
		}
		~ITEM();
		char* getName();
		int getPrice();
		int getAtribut( int x );
};



void ITEM::setName( char* newname ) // "declaration  syntax errror " and "size of 'ITEM' is unknown or zero"
{
	strcpy( name, newname );
}

void ITEM::setPrice( int newprice )
{
	price = newprice;
}

char* ITEM::getName()
{
	return name;
}

int ITEM:: getPrice()
{
	return price;
}

int ITEM::getAtribut(int x)
{
	return efatr[x];
}

void ITEM::setAtribut( int x, int ef )
{
	efatr[ x ] = ef;
}
Reply With Quote  
Posts: 314
Reputation: cikara21 is an unknown quantity at this point 
Solved Threads: 61
cikara21's Avatar
cikara21 cikara21 is offline Offline
Posting Whiz

Re: Class declaration syntax error

  #4  
Nov 24th, 2008
Semicolon is missing..
Example..
  1. class Cmy
  2. {
  3. //...
  4. }; // here
.:-cikara21-:.
Reply With Quote  
Posts: 314
Reputation: cikara21 is an unknown quantity at this point 
Solved Threads: 61
cikara21's Avatar
cikara21 cikara21 is offline Offline
Posting Whiz

Re: Class declaration syntax error

  #5  
Nov 24th, 2008
// what's this
ITEM_atribut getAtribut();






Last edited by cikara21 : Nov 24th, 2008 at 12:56 pm.
.:-cikara21-:.
Reply With Quote  
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

  #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 1:41 pm.
Reply With Quote  
Posts: 2,000
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: 331
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: Class declaration syntax error

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

Re: Class declaration syntax error

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Views: 630 | Replies: 7 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 3:02 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC