473,383 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

problem in storing objects in Map class

22
i have a class 'Root' from which i derived all other classes.

in one of derived class (HashMap), i'm using Map object to store Root objects, making it a very generic class to store any derived class object.

like:
--------
typedef map<Root, Root> Map;
Map data;

put(Root& key, Root& value)
{
data.insert(pair<Root, Root>(key, value));
}


but in the insert line, i'm getting following error:
error: no match for ‘operator<’ in ‘__x < __y’
Root.cpp:43: note: candidates are: bool Root::operator<(Root&)

i've defined: bool operator < (Root&) in Root class, along with == overload.


Please help
Jul 8 '07 #1
1 1260
weaknessforcats
9,208 Expert Mod 8TB
The Root::operator< won't cut it.

You need an operator< that has two const arguments:
Expand|Select|Wrap|Line Numbers
  1. bool operator<(const Root& lhs, const Root& rhs)
  2. {
  3.     //etc...
  4. }
  5.  
Also, map of Root objects won't work for derived classes. All that will be in the map is the Root portion of your derived object. The rest will be neatly sliced off.

I suggest a map of Root handles. Read this.
Jul 8 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Iain Bishop | last post by:
I'm trying to model objects for the following problem: A building site contains assemblies, each of which can contain other assemblies and/or materials. I have modelled this using a Site...
3
by: SB | last post by:
Hello. I have an input file which is laid out in the following manner... Name Day 1 am time 1 am time 2 appointment pm time 1 pm time 2 appointment Day 2
13
by: Joseph | last post by:
I was doing my assignment,but encountered a problem at last step!!!!!! for easy reading, i ommited lots of other things //=====================code begin================================...
3
by: DJ.precario | last post by:
Hi, I have a vector (myVector) of BaseClass objects. I store in it a DerivedClass object (where DerivedClass inherits from BaseClass). Later I want to get the last element in the vector and...
6
by: Alfonso Morra | last post by:
I have written the following code, to test the concept of storing objects in a vector. I encounter two run time errors: 1). myClass gets destructed when pushed onto the vector 2). Prog throws a...
12
by: Alfonso Morra | last post by:
I have the ff code for testing the concept of storing objects: #include <vector> #include <iostream> using namespace std ; class MyClass { public: MyClass(){
7
by: jsale | last post by:
I'm currently using ASP.NET with VS2003 and SQL Server 2003. The ASP.NET app i have made is running on IIS v6 and consists of a number of pages that allow the user to read information from the...
6
by: TPJ | last post by:
Help me please, because I really don't get it. I think it's some stupid mistake I make, but I just can't find it. I have been thinking about it for three days so far and I still haven't found any...
9
by: david | last post by:
I have a class with some business-logic and with every roundtrip, I need an instance of this class, so I have to create it, every time again. That doesn't seem very efficient. I thought it would...
3
by: RSH | last post by:
Hi, I have a situation where I have created an object that contains fields,properties and functions. After creating the object I attempted to assign it to a session variable so i could retrieve...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.