473,325 Members | 2,608 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,325 software developers and data experts.

std::map problem

In the test program below, the compiler complains that it cannot deduce the
argument when assigning an int value to an entry in a std::map. What am I doing
wrong?
#include <map>

class EntityID {

public:
unsigned int site;
unsigned int application;
unsigned int entity;
};

void main() {

std::map<EntityID,int> test;

EntityID id1;

id1.site = 6;
id1.application = 5;
id1.entity = 4;

test[id1] = 5;

EntityID id2;

id2.site = 6;
id2.application = 5;
id2.entity = 4;

std::map<EntityID,int>::const_iterator i = test.find(id2);
if ( i != test.end() ) {
printf("Test passed.\n");
} else {
printf("Test failed.\n");
}

}
Jul 22 '05 #1
2 1165
O.B. wrote:
In the test program below, the compiler complains that it cannot deduce
the argument when assigning an int value to an entry in a std::map.
What am I doing wrong?
Just a couple of things.


#include <map>

class EntityID {

public:
unsigned int site;
unsigned int application;
unsigned int entity;
};

void main() {
int main() {

std::map<EntityID,int> test;
Your 'EntityID' class doesn't have 'operator<' defined for it, and thus
it cannot be used as the key for a map. You need to define how one
EntityID object is "less" than another. RTFM.

EntityID id1;

id1.site = 6;
id1.application = 5;
id1.entity = 4;

test[id1] = 5;

EntityID id2;

id2.site = 6;
id2.application = 5;
id2.entity = 4;

std::map<EntityID,int>::const_iterator i = test.find(id2);
if ( i != test.end() ) {
printf("Test passed.\n");
} else {
printf("Test failed.\n");
}

}


V
Jul 22 '05 #2

"O.B." <fu******@bellsouth.net> wrote in message
news:10*************@corp.supernews.com...
In the test program below, the compiler complains that it cannot deduce the argument when assigning an int value to an entry in a std::map. What am I doing wrong?
#include <map>

class EntityID {

public:
unsigned int site;
unsigned int application;
unsigned int entity;
};
Modify EntityID such that the following compiles, and your code should
compile and run.

int main()
{
EntityID id1;

id1.site = 6;
id1.application = 5;
id1.entity = 4;

EntityID id2;

id2.site = 6;
id2.application = 5;
id2.entity = 4;

bool Id1LessThanId2 = id1 < id2;
bool Id2LessThanId1 = id2 < id1;

return 0;
}

Jeff F

void main() {

std::map<EntityID,int> test;

EntityID id1;

id1.site = 6;
id1.application = 5;
id1.entity = 4;

test[id1] = 5;

EntityID id2;

id2.site = 6;
id2.application = 5;
id2.entity = 4;

std::map<EntityID,int>::const_iterator i = test.find(id2);
if ( i != test.end() ) {
printf("Test passed.\n");
} else {
printf("Test failed.\n");
}

}

Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

44
by: jmoy | last post by:
I am a C programmer graduating to C++. As an exercise I wrote a program to count the number of times that different words occur in a text file. Though a hash table might have been a better choice,...
5
by: EnTn | last post by:
Hi Everyone... I've been trying to use a std::map to do some storage. Basically, i'm storing double values using a Key Object. The Key object is quite simple and is just a pair of int's...
1
by: Saeed Amrollahi | last post by:
Dear All C++ Programmers Hello I am Saeed Amrollahi. I am a software engineer in Tehran Sewerage Company. I try to use std::map and map::find member function. I use Visual Studio .NET. my...
5
by: Peter Jansson | last post by:
Hello, I have the following code: std::map<int,std::set<std::string> > k; k="1234567890"; k="2345678901"; //... std::set<std::string> myMethod(std::map<int,std::set<std::string> > k)...
19
by: Erik Wikström | last post by:
First of all, forgive me if this is the wrong place to ask this question, if it's a stupid question (it's my second week with C++), or if this is answered some place else (I've searched but not...
3
by: Dan Trowbridge | last post by:
Hi everyone, In my attempt to port code from VS 6.0 to VS.NET I had some code break along the way, mostly due to not adhereing closely to the C++ standard. This may be another instance but I...
1
by: marco_segurini | last post by:
Hi, At the moment I am using Visual Studio 2005 beta 1. The following program does not compile using the debug configuration setting the "Disable Language Extensions" flag to "Yes(/Za)" while...
13
by: kamaraj80 | last post by:
Hi I am using the std:: map as following. typedef struct _SeatRowCols { long nSeatRow; unsigned char ucSeatLetter; }SeatRowCols; typedef struct _NetData
7
by: DevNull | last post by:
Hi there everyone, I'm creating a very simple immediate mode command interpreter. The final purpose is to provide a pluggable control and command console for a MUD server I have written. The...
5
by: Chris Forone | last post by:
Hello group, g++ (3.4.2, mingw): float init = {1.f, 2.f, 3.f}; std::map<std::string, std::valarray<float mp; mp = std::valarray(init, 3); mp.size(); // should be 3, but IS 0!
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.