DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   Class declaration syntax error (http://www.daniweb.com/forums/thread159083.html)

Nickyu0712 Nov 23rd, 2008 12:37 pm
Class declaration syntax error
 
#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??

mrboolf Nov 23rd, 2008 1:24 pm
Re: Class declaration syntax error
 
You are missing semicolon
;
after your class' closing bracket and the assignment
name = "Player";
should be
strcpy(name, "Player");

Nickyu0712 Nov 24th, 2008 1:31 pm
Re: Class declaration syntax error
 
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;
}

cikara21 Nov 24th, 2008 1:50 pm
Re: Class declaration syntax error
 
Semicolon is missing..
Example..
class Cmy
{
  //...
}; // here

cikara21 Nov 24th, 2008 1:56 pm
Re: Class declaration syntax error
 
// what's this
ITEM_atribut getAtribut();

mrboolf Nov 24th, 2008 2:37 pm
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;
?

ArkM Nov 24th, 2008 2:41 pm
Re: Class declaration syntax error
 
I see a very bad class design and implementation but no any compile-time errors ;)...

Nickyu0712 Nov 25th, 2008 2:30 pm
Re: Class declaration syntax error
 
Quote:

Originally Posted by mrboolf (Post 743640)
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


All times are GMT -4. The time now is 10:19 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC