GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 31-May-2005, 12:16
Krandygrl00 Krandygrl00 is offline
Junior Member
 
Join Date: May 2005
Location: chicago, il
Posts: 39
Krandygrl00 is on a distinguished road
Question

Help with compiler errors


**My code does NOT complile...I need help on the compile errors**
1. error C2676: binary '==' : 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' does not define this operator or a conversion to a type accep
table to the predefined operator

2. error C2440: '=' : cannot convert from 'class Seller *' to 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

**Having problems with entering info(string) about the items to be auctioned, search using an id number and remove...when i enter the string it gives me binary back when i dont have the compile errors...Please help I do not understand my compile errors

****MY CODE(part)***
CPP / C++ / C Code:
#include <iostream>
#include <string>
using namespace std;

class Seller : public User
{
private:
	string payment;												//type of payment
	string storeName;											//name of store item was bought from
	int idNum;													//id number for items
	int maxSize;
	int length;
	string *list;
public:
	void setPayInfo(string pay, string name, int num);			//set pay information
	void print()const;											//print pay information
	Seller& setPayment(string pay);								//set payment type
	Seller& setStoreName(string name);							//set store name
	Seller& setIdNumb(int num);									//set id number
	void getPayInfo(string& pay, string& name, int& num);		//get pay information
	Seller(string pay = "", string name = "", int num = 0, int size = 500);		//constructor
	void insert(string item, int idNum, string tell);			//add an item to the list
	void remove(const idNum);									//remove an item from the list
	void displayItems() const;									//display the descriptions and id 
	void removeAt(int location);								//removes items at a specific location
	int seqSearch(const idNum);									//searches for id number
	const Seller& operator=(const Seller&);						//overload the assignmnet operator
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Seller& Seller::setPayment(string pay)
{
	payment = pay;
	return *this;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Seller::print()const
{
	cout << "METHOD of PAYMENT: " << payment;
	cout << endl;
	cout << "STORE NAME: " << storeName;
	cout << endl;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Seller::setPayInfo(string pay, string name, int num)
{
	payment = pay;
	storeName = name;
	idNum = num;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Seller::getPayInfo(string& pay, string& name, int& num)
{
	pay = payment;
	name = storeName;
	num = idNum;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Seller::Seller(string pay, string name, int num, int size)
{
	payment = pay;
	storeName = name;
	idNum = num;
	size = size;
	length = 0;

	if(size <= 0)
		maxSize = 500;
	else
		maxSize = size;

	list = new string[maxSize];
//	assert(list != NULL);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Seller& Seller::setStoreName(string name)
{
	storeName = name;
	return *this;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Seller& Seller::setIdNumb(int num)
{
	idNum = num;
	return *this;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Seller::displayItems() const
{
	if(length == 0)
		cout << "List is empty." << endl;
	else
	{
		for(int i = 0; i < length; i++)
			cout << list[i] << " ";
		cout << endl;
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Seller::insert(string item, int idNum, string tell)
{
	if(length == maxSize)
		cout << "List is full." << endl;
	else
		list[length++] = item;
		list[length++] = idNum;
		list[length++] = tell;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Seller::removeAt(int location)
{
	if(location < 0 || location >= length)
		cerr << "The item is not in the list." << endl;
	else
	{
		for(int i = location; i < length - 1; i++)
			list[i] = list[i + 1];
		length--;
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Seller::remove(const idNum)
{
	int loc;

	if(length == 0)
		cerr << "Empty list." << endl;
	else 
	{
		loc = seqSearch(idNum);

		if(loc != -1)
			removeAt(loc);
		else
			cout << "Item not in list." << endl;
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int Seller::seqSearch(const idNum)
{
	int loc;
	bool found = false;

	for(loc = 0; loc < length; loc++)
		if(list[loc] == idNum)
		{
			found = true;
			break;
		}
		if(found)
			return loc;
		else
			return -1;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const Seller& Seller::operator =(const Seller& otherList)
{
	if(this != &otherList)
	{
		delete [] list;
		maxSize = otherList.maxSize;
		length = otherList.length;

		list = new Seller[maxSize];
		//assert(list != NULL);

		for(int i = 0; i < length; i++)
			list[i] = otherList.list[i];
	}
	return *this;

}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------------------------------------------------------------------------------

int main()
{
	char ans;
	int idNum;
	string tell;
	string item;
	Seller list;

	cout << "This Is An Online Auction Site!" << endl;
	cout << endl;
	

	do{
	cout << "Please enter an Item: ";
	cin >> item;
	cout << endl;
	cout << "Desctiption: ";
	cin >> tell;
	cout << endl;
	cout << "Id Number: ";
	cin >> idNum;
	cout << endl;
	cout << "Enter another Item(y/n)?: ";
	cin >> ans;
	list.insert(item, idNum, tell);							//enters item and its information into the array
	}while(ans != 'n');
	return 0;
}
Last edited by LuciWiz : 31-May-2005 at 14:34. Reason: Please insert your C++ code between [c++] & [/c++] tags
  #2  
Old 31-May-2005, 13:55
QED's Avatar
QED QED is offline
Member
 
Join Date: Feb 2005
Location: Hudson Valley, NY
Posts: 231
QED is a jewel in the roughQED is a jewel in the roughQED is a jewel in the rough
If you can include line numbers with future error messages (your compiler should report this, I think), it will be easier to address your questions.

The code as you posted it caused a few other compile-time errors for me, using g++ 3.3.5. In the following line
CPP / C++ / C Code:
class Seller : public User
the symbol "User" has not been defined. Is there another include statement that is missing here?

Commenting out the ": public User" part and moving on, I also found that the "remove" and "seqSearch" methods did not specify a type for the parameter "idNum".
CPP / C++ / C Code:
void remove(const idNum); //remove an item from the list
int seqSearch(const idNum); //searches for id number
I assumed that your intention was the following
CPP / C++ / C Code:
void remove(int const idNum); //remove an item from the list
int seqSearch(int const idNum); //searches for id number
With these changes, my compiler then gave the following error message:
Code:
test_Krandygrl00.cpp: In member function `int Seller::seqSearch(int)': test_Krandygrl00.cpp:163: error: no match for 'operator==' in '*(this->Seller::list + (+(loc * 4))) == idNum'
For me line 163 was the following from the definition of the method "seqSearch":
CPP / C++ / C Code:
if(list[loc] == idNum)
In this case, "list" is a pointer-to-std::string object, "list[loc]" is thus a std::string object, and idNum is an int. The message is telling us, roughly, that we cannot compare a string to an int using "==". This is the equivalent of your first error message.

The second error message is similar. It refers to the line
CPP / C++ / C Code:
list = new Seller[maxSize]
and means that since "list" is a pointer-to-string, we can not assign to it a pointer-to-Seller, which is what we get here. (Or, more clearly in this case, we can't assign an array of Seller objects to an array of string objects.)

I hope this helps, and will be happy to try answering other questions (including those about my lengthy answers ).

Matthew
  #3  
Old 31-May-2005, 15:22
Krandygrl00 Krandygrl00 is offline
Junior Member
 
Join Date: May 2005
Location: chicago, il
Posts: 39
Krandygrl00 is on a distinguished road

compiler errors to Matthew


I understand you can not compare strings to ints BUT I guess what im tryin to ask is that how do i search for a string by using the idNum....for example

Please enter the id number for the item u want to delete
id number is entered
if id number is equal to the idnumber entered
delete

if not make sense tell me
PS my whole code wasnt listed user is a class defined sorry
  #4  
Old 01-Jun-2005, 07:45
QED's Avatar
QED QED is offline
Member
 
Join Date: Feb 2005
Location: Hudson Valley, NY
Posts: 231
QED is a jewel in the roughQED is a jewel in the roughQED is a jewel in the rough
So, you want each item that is for sale to have a (presumable unique) ID number associated with it. I notice that each Seller also has its own ID number. In this case, try using more specific variable names to avoid confusion over which ID number is in question.

Now for your problem of finding items in the list by ID... As with any problem, programming included, there are several ways to do this; I will mention two that I can think of, but you may be able to come up with your own that suits your problem better.

Method 1)
Keep multiple "lists" (or arrays), one for item name, one for item ID, etc. In this scenario, you need to make sure that all the lists are synchronized; that is, they have the same length, and when you add/remove/modify one list that you also do the same for the others. While this can work, I find it tedious, error-prone, and do not recommend it, though it may seem like more work initially to design the Item class and how it should interact with the rest of your program.

Method 2)
Create a new structure for items, for example "class Item". This class will contain the string name of the item, the ID number, etc. THen you require only one list, which could then be an array of Item objects. Of course, you need to consider all kinds of new things, such as how to create an Item (with a constructor that takes a string, int, etc. as parameters), and how to retrieve the name, or ID, from the Item object if necessary. I recommend this method.

I'll be happy to clarify if you don't quite follow me here.

Matthew
 
 

Recent GIDBlogObservations of Iraq by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ PhoneBook marita C++ Forum 46 12-Jun-2005 12:10
Newbie : need help with Dev-C++ compiler batrsau C++ Forum 2 20-Mar-2005 21:05
compiler errors Newworld C Programming Language 1 28-Oct-2004 07:07
help to debug complier errors nkhambal C Programming Language 3 04-Oct-2004 08:26
a noobish compiler question Charunks C++ Forum 5 03-Sep-2003 02:18

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:57.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.