C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 03-26-2002, 02:47 PM   #1
Unregistered
Guest
 
Posts: n/a
operator==

I'm trying to overload the operator== from a struct that i have made. I hold the struct's in a std::list -->> list<Record>My_Rec_List;
-----------------------------------------------

Trying to do:
if ( iter == My_Rec_List.front() )

------------------------------------------------
what i have (defined in the struct):

friend bool operator==(Record r, const Record &IN2){
return r.First_number == IN2.First_number;
}


VC++ 6.0 error
--------------------
error C2678: binary '==' : no operator defined which takes a left-hand operand of type 'class std::list<struct Record,class std::allocator<struct Record> >::iterator' (or there is no acceptable conversion)
Error executing cl.exe.
  Reply With Quote
Old 03-26-2002, 03:26 PM   #2
Unregistered
Guest
 
Posts: n/a
better yet,

writing the record....

what iter x is pointing to is what i need to write...

Writes garbage but the only thing i can get to compile

Code:
SfileS.write((char*)(&x), sizeof(Record));
  Reply With Quote
Old 03-26-2002, 03:49 PM   #3
S­énior Member
 
Join Date: Jan 2002
Posts: 982
>Trying to do:
if ( iter == My_Rec_List.front() ) <

You'll have to use the operator* on iter.

>what iter x is pointing to is what i need to write...<

You could overload operator>> and operator<< to read/write a Records elements to file.
Sorensen is offline   Reply With Quote
Old 03-26-2002, 04:42 PM   #4
Unregistered
Guest
 
Posts: n/a
Quote:
You could overload operator>> and operator<< to read/write a Records elements to file.
Can i do that, but still write in Binary mode ?
  Reply With Quote
Old 03-26-2002, 05:24 PM   #5
S­énior Member
 
Join Date: Jan 2002
Posts: 982
No if you really need to read/write in binary, then you need to do something like -

Code:
#include <iostream>
#include <fstream>

using namespace std;

struct TwoInts
{
	int a;
	int b;
};

int main()
{
	ofstream os("ti.bin",ios::binary);
	TwoInts one={1,2};
	os.write((char *)&one,sizeof(one));
	os.close();

	ifstream is("ti.bin",ios::binary);
	TwoInts two;
	is.read((char*)&two,sizeof(two));

	cout << two.a << ' ' << two.b << '\n';

	return 0;
}
Sorensen is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
operator== Tux0r C++ Programming 17 07-09-2009 02:29 AM
stl error eklavya8 C++ Programming 8 06-30-2008 12:01 PM
"error: incomplete type is not allowed" Fahrenheit C++ Programming 9 05-10-2005 09:52 PM
Problem with Template Function and overloaded equality operator silk.odyssey C++ Programming 7 06-08-2004 04:30 AM


All times are GMT -6. The time now is 05:13 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22