Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

associative containers and templates

Status
Not open for further replies.

Tracey

Programmer
Oct 16, 2000
690
NZ
hi

im a little stuck at the moment i wonder if someone can help

in recordtemplate.h i have the following template

template <class RecordType> class RecordClass
{
private:
AnsiString theFileName;

public:
//contructor
RecordClass(){};

//Destructor
~RecordClass(){};
};

in uTenant.h i have the class

//declare the tenant records
class TenantRecord : public RecordClass<AnsiString>
{
private:
public:
char FName[50];
char LName[50];
int Apartment;
};

and in uTenant.cpp :

//create an i/o file
fstream TenantFile;

// create a set of tenant records
set <TenantRecord, less<TenantRecord> > TTenants;

//create and iterator to the set of expense records
set <TenantRecord, less<TenantRecord> >::iterator teniter;

void __fastcall TfrmTenant::btnSaveClick(TObject *Sender)
{
TenantRecord thisrecord;

strcpy(thisrecord.FName,edtFName->Text.c_str());
strcpy(thisrecord.LName, edtLName->Text.c_str());
thisrecord.Apartment = StrToInt(edtApartment->Text);
TTenants.insert(thisrecord);
}

i am getting a compile error on the insert, which seems to be complaining about the &quot;less&quot; in the set.

[C++ Error] function.h(169): E2093 'operator<' not implemented in type 'TenantRecord' for arguments of the same type

what am i doing wrong.. I understand i need to use an iterator but have the same problem when i use it. I am just learning associative containers and templates and am very lost at this point. Pleeeeze help [cry]








 
Looks like it wants you to overload operator< for your TenantRecord class.

The function object &quot;less&quot; uses that operator to compare its operands. When you instantiate the template, it generates some code that says &quot;a < b&quot;, where a and b are TenantRecord objects. Since there's no operator< that takes two TenantRecords, that expression doesn't work. That's what it's complaining about. You define an operator that takes those arguments to remedy the situation.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top