   Why is this telling me it's missing storage class or type specifiers?
  Code:   #ifndef ITEM#define ITEM#include <string>#define MAXINV 10class Item {private:string desc;double weight;public://Constructors/DestructorItem():desc="",weight=0{}Item(string d, double w);~Item();//Accessor functionsstring getdesc(){return desc;}double getweight(){return weight;}//Functionsvoid setdesc(string d);void setweight(double w);};class Inventory {private:Item inv[MAXINV];public:Inventory(){for(int i=0;i<MAXINV;i++)inv[i]=Item();}Inventory(Item i[]);//Accessor functionvoid getinv() {return inv;}//Functionsvoid add(Item i, int slot);void remove(int slot);};#endif    Errors:c:\Programs\Games\RPGClasses\Item.h(7): error C2146: syntax error : missing ';' before identifier 'desc'c:\Programs\Games\RPGClasses\Item.h(7): error C2501: 'Item::desc' : missing storage-class or type specifiersc:\Programs\Games\RPGClasses\Item.h(7): error C2501: 'Item::string' : missing storage-class or type specifiersc:\Programs\Games\RPGClasses\Item.h(11): error C2059: syntax error : 'string'c:\Programs\Games\RPGClasses\Item.h(11): error C2334: unexpected token(s) preceding '{'; skipping apparent function bodyc:\Programs\Games\RPGClasses\Item.h(11): error C2969: syntax error : '=' : expected member function definition to end with '}'c:\Programs\Games\RPGClasses\Item.h(12): error C2238: unexpected token(s) preceding ';'c:\Programs\Games\RPGClasses\Item.h(12): error C2629: unexpected 'Item ('c:\Programs\Games\RPGClasses\Item.h(16): error C2146: syntax error : missing ';' before identifier 'getdesc'c:\Programs\Games\RPGClasses\Item.h(16): error C2501: 'Item::string' : missing storage-class or type specifiersc:\Programs\Games\RPGClasses\Item.h(18): warning C4183: 'getdesc': missing return type; assumed to be a member function returning 'int'c:\Programs\Games\RPGClasses\Item.h(25): error C2061: syntax error : identifier 'string'I imagine if i fix whats wrong it will fix everything, but i cant figure out whats wrong.[edited by - Nanven on May 27, 2003 1:37:26 AM]
string = char[] or char*no string in C or C++, use one of the above.  Probably the array.{particleG}  ;quote:Original post by particleG  string = char[] or char*no string in C or C++, use one of the above.  Probably the array.{particleG} Wrong. No string in C.The original poster forgot to prepend std:: to string:string desc;   should be std::string desc; ;  You need to use std::string if you want to use the strings from STL.  ;  Ya, figured i was missing std right after i posted this, how dumb of me heh  ;  not only that, but I don''t think = operators are allowed in the initialization list.i.e.: instead of this: Item() : desc = "", weight = 0 {}  do this:Item() : desc( "" ), weight( 0 ) {} ;  Your Inventory constructor is screwy. Are you coming from a Java background? In C++ we distinguish between objects and references (or pointers) to those objects. Where you assign a new Item object (created via explicit constructor invocation) to each element of inv, you''re playing havok with your system. When you perform an assignment in C++ on a data type that lacks a native assignment operator (and copy constructor as a fallback), the compiler supplies a default which performs a bitwise copy. Which may not be desired behavior.  ;  Nah, it was just a very early version of the class, heres my new one:   //|----------------------------------------------------|//|---Item.h - Item and Inventory class declarations---|//|----------------------------------------------------|//Make sure header is only defined once#ifndef ITEM#define ITEM//Header files#include <string>#include <iostream>using namespace std;//Macro for max inventory space#define MAXINV 10//|----------------|//|---Class Item---|//|----------------|class Item {private://Attributesstring desc;double weight;public://Constructors/DestructorItem():desc(""),weight(0) {}Item(const string &d, double w);~Item();//Accessor functionsstring getdesc() {return desc;}double getweight() {return weight;}//Functionsvoid setdesc(const string &d);void setweight(double w);void clear();//Overloaded operatorsfriend bool operator==(const Item &first,const Item &last) {if(first.desc == last.desc && first.weight == last.weight)return true;return false;}};//|---------------------|//|---Class Inventory---|//|---------------------|class Inventory {private://AttributesItem inv[MAXINV];public:Inventory() {for(int i=0;i<MAXINV;i++)inv[i].clear();}//Copy constructorInventory(const Inventory &i);//Function declarationsvoid add(const Item &i, int slot);void remove(int slot);void display();int findslot();int finditem(const Item &i);};#endif  