Start New Discussion within our Software Development Community

I keep getting this error message about intializing a varible as a string type:

`string' does not name a type

I cant figure out how to get rid of it even though i have #include<string>
any help would be great:

#include <string>
#include <fstream>

int MAX_ITEMS = 5;
enum RelationType  {LESS, GREATER, EQUAL};
class ItemType
{
      public:
			
		   ItemType();
           RelationType ComparedTo();
           void PromoteMe();
		   void DemoteMe();

      private:
			  string company;
              string name;
              int rank;
              int total;
};

ItemType :: ItemType(string myName,string myCompany)
{
        name = myName;
        company = myCompany;
        rank = 1;
        total = 0;
}

RelationType ItemType::ComparedTo(ItemType otherObj)
{
        if((company < otherObj.company)||(company == otherObj.company)
        &&(rank < otherObj.rank))
              return LESS;
        else if((company > otherObj.company)||(company == otherObj.company)
        && (rank > otherObj.rank))
              return GREATER;
        else
              return EQUAL;
}

void ItemType::PromoteMe()
{
    rank = rank + 1;
}

void ItemType::DemoteMe()
{
	rank = rank-1;
}

string is in the std namespace, so you need to qualify each use of that name in one of three ways:

// Per-use qualification
std::string a;
std::string b;
// using declaration
using std::string;

string a;
string b;
// using directive
using namespace std;

string a;
string b;

The difference between a using declaration and a using directive is that the using directive qualifies all names in the namespace while a using declaration only qualifies the name you specify.

This article has been dead for over six months. Start a new discussion instead.