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

Recommended Answers

All 7 Replies

You are missing semicolon ; after your class' closing bracket and the assignment name = "Player"; should be strcpy(name, "Player");

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;
}

Semicolon is missing..
Example..

class Cmy
{
   //...
}; // here
// what's this
ITEM_atribut getAtribut();

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; ?

I see a very bad class design and implementation but no any compile-time errors ;)...

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.