473,545 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem using std::map

Hi
I am using the std:: map as following.

typedef struct _SeatRowCols
{
long nSeatRow;
unsigned char ucSeatLetter;
}SeatRowCols;

typedef struct _NetData
{
SeatRowCols tSeatRowCols;
unsigned char ucMacAddress[MAC_LENGTH];
unsigned char ucAdminStatus;
unsigned char ucLocalFault;

}NetData;

typedef std::map <SeatRowCols, PedData> MAP_PED_DATA;
..........
.............

MAP_PED_DATA data;
PedData pdata;
SeatRowCols sdata;

memset((void*)& sdata,0,sizeof( SeatRowCols));
sdata.nSeatRow =1;
sdata.ucSeatLet ter ='A';
memset((void*)& pdata,0,sizeof( PedData));
pdata.nPortClas s = 1;
pdata.tSeatRowC ols = sdata;
data[sdata] = pdata;

while compiling this code the following error are occurs.

Compiling...
DemoOfDatatStru ctures.cpp
E:\testprjs\tes tit\DemoOfDatat Structures\Demo OfDatatStructur es.cpp(79)
: warning C4786:
'std::reverse_b idirectional_it erator<std::_Tr ee<_SeatRowCols ,std::pair<_Sea tRowCols
const
,_PedData>,std: :map<_SeatRowCo ls,_PedData,std ::less<_SeatRow Cols>,std::
allocator<_PedD ata>
::_Kfn,std::le ss<_SeatRowCols >,std::allocato r<_PedData> >::iterator,std ::pair<_SeatRow Cols const ,_PedData>,std: :pair<_SeatRowC ols const ,_PedData> &,std::pair<_Se atRowCols const ,_PedData> *,int>' : identifier was truncated to '255' characters in the debug information
E:\testprjs\tes tit\DemoOfDatat Structures\Demo OfDatatStructur es.cpp(79)
: warning C4786:
'std::reverse_b idirectional_it erator<std::_Tr ee<_SeatRowCols ,std::pair<_Sea tRowCols
const
,_PedData>,std: :map<_SeatRowCo ls,_PedData,std ::less<_SeatRow Cols>,std::
allocator<_PedD ata>::_Kfn,std::le ss<_SeatRowCols >,std::allocato r<_PedData> >::const_iterat or,std::pair<_S eatRowCols const ,_PedData>,std: :pair<_SeatRowC ols const ,_PedData> const &,std::pair<_Se atRowCols const ,_PedData> const *,int>' : identifier was truncated to '255' characters in the debug information
E:\testprjs\tes tit\DemoOfDatat Structures\Demo OfDatatStructur es.cpp(79)
: warning C4786:
'std::pair<std: :_Tree<_SeatRow Cols,std::pair< _SeatRowCols const
,_PedData>,std: :map<_SeatRowCo ls,_PedData,std ::less<_SeatRow Cols>,std::allo cator<_PedData>::_Kf n,std::less<_Se atRowCols>,std: :allocator<_Ped Data>::iterator,std ::_Tree<_SeatRo wCols,std::pair <_SeatRowCols const ,_PedData>,std: :map<_SeatRowCo ls,_PedData,std ::less<_SeatRow Cols>,std::allo cator<_PedData> >::_Kfn,std::le ss<_SeatRowCols >,std::alloc ator<_PedData> >::iterator>' : identifier was truncated to '255'
characters in the debug information
E:\testprjs\tes tit\DemoOfDatat Structures\Demo OfDatatStructur es.cpp(79)
: warning C4786:
'std::pair<std: :_Tree<_SeatRow Cols,std::pair< _SeatRowCols const
,_PedData>,std: :map<_SeatRowCo ls,_PedData,std ::less<_SeatRow Cols>,std::allo cator<_PedData>::_Kf n,std::less<_Se atRowCols>,std: :allocator<_Ped Data>::const_iterat or,std::_Tree<_ SeatRowCols,std ::pair<_SeatRow Cols const ,_PedData>,std: :map<_SeatRowCo ls,_PedData,std ::less<_SeatRow Cols>,std::allo cator<_PedData> >::_Kfn,std::le ss<_SeatRowCols >,std:

:allocator<_Ped Data> >::const_iterat or>' : identifier was truncated to
'255' characters in the debug information
e:\program files\microsoft visual studio\vc98\inc lude\functional (86) :
error C2784: 'bool __cdecl std::operator <(const class
std::multimap<_ K,_Ty,_Pr,_A> &,const class std::multimap<_ K,_Ty,_Pr,_A>
&)' : could not deduce template argument for 'const
class std::multimap<_ K,_Ty,_Pr,_A> &' from 'const struct _SeatRowCols'
e:\program files\microsoft visual
studio\vc98\inc lude\functional (86) : while compiling class-template
member function 'bool __thiscall std::less<struc t
_SeatRowCols>:: operator ()(const struct _SeatRowCols &,const struct
_SeatRowCols &) const
'
e:\program files\microsoft visual studio\vc98\inc lude\functional (86) :
error C2784: 'bool __cdecl std::operator <(const class
std::map<_K,_Ty ,_Pr,_A> &,const class std::map<_K,_Ty ,_Pr,_A> &)' :
could not deduce template argument for 'const class std
::map<_K,_Ty,_P r,_A> &' from 'const struct _SeatRowCols'
e:\program files\microsoft visual
studio\vc98\inc lude\functional (86) : while compiling class-template
member function 'bool __thiscall std::less<struc t
_SeatRowCols>:: operator ()(const struct _SeatRowCols &,const struct
_SeatRowCols &) const
'
e:\program files\microsoft visual studio\vc98\inc lude\functional (86) :
error C2784: 'bool __cdecl std::operator <(const class
std::_Tree<_K,_ Ty,_Kfn,_Pr,_A> &,const class
std::_Tree<_K,_ Ty,_Kfn,_Pr,_A> &)' : could not deduce template argument
for 'c
onst class std::_Tree<_K,_ Ty,_Kfn,_Pr,_A> &' from 'const struct
_SeatRowCols'
e:\program files\microsoft visual
studio\vc98\inc lude\functional (86) : while compiling class-template
member function 'bool __thiscall std::less<struc t
_SeatRowCols>:: operator ()(const struct _SeatRowCols &,const struct
_SeatRowCols &) const
'
e:\program files\microsoft visual studio\vc98\inc lude\functional (86) :
error C2784: 'bool __cdecl std::operator <(const class
std::reverse_it erator<_RI,_Ty, _Rt,_Pt,_D> &,const class
std::reverse_it erator<_RI,_Ty, _Rt,_Pt,_D> &)' : could not deduce te
mplate argument for 'const class
std::reverse_it erator<_RI,_Ty, _Rt,_Pt,_D> &' from 'const struct
_SeatRowCols'
e:\program files\microsoft visual
studio\vc98\inc lude\functional (86) : while compiling class-template
member function 'bool __thiscall std::less<struc t
_SeatRowCols>:: operator ()(const struct _SeatRowCols &,const struct
_SeatRowCols &) const
'
e:\program files\microsoft visual studio\vc98\inc lude\functional (86) :
error C2784: 'bool __cdecl std::operator <(const struct
std::pair<_T1,_ T2> &,const struct std::pair<_T1,_ T2> &)' : could not
deduce template argument for 'const struct std::pair<
_T1,_T2> &' from 'const struct _SeatRowCols'
e:\program files\microsoft visual
studio\vc98\inc lude\functional (86) : while compiling class-template
member function 'bool __thiscall std::less<struc t
_SeatRowCols>:: operator ()(const struct _SeatRowCols &,const struct
_SeatRowCols &) const
'
e:\program files\microsoft visual studio\vc98\inc lude\functional (86) :
error C2784: 'bool __cdecl operator <(_Interface *,class
_com_ptr_t<_Int erfacePtr> &)' : could not deduce template argument for
' *' from 'const struct _SeatRowCols'
e:\program files\microsoft visual
studio\vc98\inc lude\functional (86) : while compiling class-template
member function 'bool __thiscall std::less<struc t
_SeatRowCols>:: operator ()(const struct _SeatRowCols &,const struct
_SeatRowCols &) const
'
e:\program files\microsoft visual studio\vc98\inc lude\functional (86) :
error C2784: 'bool __cdecl operator <(int,class _com_ptr_t<_Int erface>
&)' : could not deduce template argument for 'overloaded function type'
from 'overloaded function type'
e:\program files\microsoft visual
studio\vc98\inc lude\functional (86) : while compiling class-template
member function 'bool __thiscall std::less<struc t
_SeatRowCols>:: operator ()(const struct _SeatRowCols &,const struct
_SeatRowCols &) const
'
e:\program files\microsoft visual studio\vc98\inc lude\functional (86) :
error C2676: binary '<' : 'const struct _SeatRowCols' does not define
this operator or a conversion to a type acceptable to the predefined
operator
e:\program files\microsoft visual
studio\vc98\inc lude\functional (86) : while compiling class-template
member function 'bool __thiscall std::less<struc t
_SeatRowCols>:: operator ()(const struct _SeatRowCols &,const struct
_SeatRowCols &) const
'
Error executing cl.exe.
Please gimme some suggestions.

Regards
kamaraj.M

Jan 6 '06 #1
13 9639

ka*******@gmail .com wrote:
Hi
I am using the std:: map as following.

typedef struct _SeatRowCols
{
long nSeatRow;
unsigned char ucSeatLetter;
}SeatRowCols;

typedef struct _NetData
{
SeatRowCols tSeatRowCols;
unsigned char ucMacAddress[MAC_LENGTH];
unsigned char ucAdminStatus;
unsigned char ucLocalFault;

}NetData;

That is very much a "C" way of defining a struct. That's not to say
it's wrong, perhaps you
are writing a library that can be used for C as well as C++. If that is
not the case then perhaps
you should use C++ classes.
typedef std::map <SeatRowCols, PedData> MAP_PED_DATA;
I don't know what PedData is but in any case as std::map is a sorted
container it needs a means
by which to sort. You have 4 ways to achieve this:

1. Overload operator < for your struct SeatRowCols.
2. Specialise std::less for SeatRowCols.
3. Write your own comparison function or functor and pass it to
std::map as the 3rd parameter.
This last method is preferred if there's more than one way to sort a
SeatRowCols.
4 (not advised): Provide an operator overload for double() or long()
that returns a sortable value.
From the rest of the code it appears you are writing in C apart from

your use of std::map. Although
I agree you might want to provide a C interface to a library, I would
suggest that once you choose to
implement in C++, you use C++ all the way through the implementation
unless you reach a
performance-critical situation where profiling shows that the C
approach is faster (or if the C approach
is a lot clearer, which in your case it isn't most of the time).

Jan 6 '06 #2
Sorry, a small correction, the structure name is not NetData, that is
PedData

typedef struct _PedData
{
SeatRowCols tSeatRowCols;
unsigned char ucMacAddress[MAC_LENGTH];
unsigned char ucAdminStatus;
unsigned char ucLocalFault;
}PedData

Jan 6 '06 #3
ka*******@gmail .com wrote:
Sorry, a small correction, the structure name is not NetData, that is
PedData

typedef struct _PedData
{
SeatRowCols tSeatRowCols;
unsigned char ucMacAddress[MAC_LENGTH];
unsigned char ucAdminStatus;
unsigned char ucLocalFault;
}PedData


Prefer not to prefix identifiers with an underscore. Often the
identifier will be reserved for the implementation. Just stick the
underscore on the end, although that's often convention for private
member variables.

In this case, you don't even need to identify the struct, since you are
typedefing it:

typedef struct {
SeatRowCols tSeatRowCols;
unsigned char ucMacAddress[MAC_LENGTH];
unsigned char ucAdminStatus;
unsigned char ucLocalFault;
} PedData;

If this is only used in C++ code (and not C), you can prefer the following:

struct PedData {
SeatRowCols tSeatRowCols;
unsigned char ucMacAddress[MAC_LENGTH];
unsigned char ucAdminStatus;
unsigned char ucLocalFault;
};

Ben Pope
--
I'm not just a number. To many, I'm known as a string...
Jan 6 '06 #4
I am using this structure inside a COM Component. So we can use C++
style coding, right?

Jan 6 '06 #5
to use map with non POD datatype you have to declare and implement the
operator less (<) for key type. POD types have this operator as
compiler built-in.

typedef struct _SeatRowCols
{
long nSeatRow;
unsigned char ucSeatLetter;
bool operator()(cons t _SeatRowCols &left, const _SeatRowCols
&right) const
{

// define your comparsion conditions for the "SeatRowCol s"
// you can't write just "return false" as it'll lead only one item
in your "map" :)

}
}SeatRowCols;

typedef std::map <SeatRowCols, NetData> MAP_PED_DATA;

Might be it is good idea to use pointer or reference to "NetData *" or
"NetData &" to avoid extra copy of NetData. I usually use poiunters.

typedef std::map <SeatRowCols, NetData *> MAP_PED_DATA;

Regards, Pavel

Jan 6 '06 #6
>>>1. Overload operator < for your struct SeatRowCols

Thanx for the valuable suggestion, I get improved my code, now it is
working after overloading the operator <. But
Why we need to overload the < operator. Has it doing anything inside
the map?
Pl explain me.

kamaraj

Jan 6 '06 #7
ka*******@gmail .com wrote:
1. Overload operator < for your struct SeatRowCols


Thanx for the valuable suggestion, I get improved my code, now it is
working after overloading the operator <. But
Why we need to overload the < operator. Has it doing anything inside
the map?


You removed this part of the quotation:
"I don't know what PedData is but in any case as std::map is a sorted
container it needs a means by which to sort. You have 4 ways to achieve
this:"

So, I think the question was already answered.

Ben Pope
--
I'm not just a number. To many, I'm known as a string...
Jan 6 '06 #8
<ka*******@gmai l.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
1. Overload operator < for your struct SeatRowCols


Thanx for the valuable suggestion, I get improved my code, now it is
working after overloading the operator <. But
Why we need to overload the < operator. Has it doing anything inside
the map?
Pl explain me.

kamaraj


Maps are sorted containers. The map apparently uses less than < to sort.
So you need to override less than < so map knows how to sort it.

Consider, how do you sort two characters? Since char is a type of number
you use less than.
char1 < char2
How do you sort intergers/floats?
num1 < num2
How do you sort some class?
class1 < class2

so you need to have the less than overridden.
Jan 7 '06 #9

ka*******@gmail .com wrote:
Sorry, a small correction, the structure name is not NetData, that is
PedData

typedef struct _PedData
{
SeatRowCols tSeatRowCols;
unsigned char ucMacAddress[MAC_LENGTH];
unsigned char ucAdminStatus;
unsigned char ucLocalFault;
}PedData


and needs a semicolon terminator.

Doesn't change the answers in my previous post. By the way, I don't
know what MAC_LENGTH is but it's better if you avoid #defines and use
either enum or const size_t. If this isn't needed for C then it should
also be enclosed at either class or namespace scope.

Jan 7 '06 #10

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

Similar topics

5
29247
by: Christopher | last post by:
I am having problems iterating through the sequence of objects stored in my std::map I want to call a function from the "value" object in the map. Here is my snippet: typedef std::map<SOCKET, Player> PLAYERMAP_SOCKET; ..... BOOL Player::Send(std::string data) ...... // Send the text to all clients
3
30018
by: Woodster | last post by:
I have declared the following std::map<std::string, std::string> myMap; to pass myMap to functions should I be declaring functions as: void function(std::map<std::string, std::string>); or is there a preferred/better method of doing this?
2
2274
by: Weddick | last post by:
I decided to try creating a map with microsoft visual C++ 6. When building this small app I get 95 warnings which make no sense to me. Anybody else see this before? Thanks, // CODE SAMPLE #include <map> #include <string>
0
1868
by: Erik Arner | last post by:
Hi, let's say I have a std::map<std::string,int> and I want to search the map for all keys that start with "foo". The regexp equivalent is to search for "foo*", or perhaps "^foo*". At present I do this quick'n'dirty by appending a tilde (~) to the query term, since I know it's last in the ascii table and my keys don't include any special...
2
3389
by: Serengeti | last post by:
Hello, in my class I have a map that translates strings to pointers to some member functions. The code goes like this: class F { typedef void (Function::*MathFuncPtr)(); std::map<std::string, MathFuncPtr> predefinedFunctions; // lots of other stuff void makeDictionary(){ predefinedFunctions=&F::f_sin(); } };
1
6460
by: Avery Fong | last post by:
The following program will result in a compile error when building under Debug but will compile under Release. Why does is work under Release mode but not under Debug This program is developed under Visual Studio .NET 2003 in a Win32 Console Project // VectorInsert.cpp : Defines the entry point for the console application / #include...
4
6236
by: Evyn | last post by:
Hi all, I'm starting to fool around with STL and in particular std::map. How do I iterate through one map and insert every pair in another map? I have the following so far: map<double, doublefset1; map<double, doublefset3;
7
6248
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 basic theory is we wrap the functions we want exposed to the console in a function with a prototype of int func(State*)
2
5365
by: digz | last post by:
Hi, I am trying to write a program which has two threads one of them write to a map , and the other one deletes entries based on a certain criterion.. first I cannot get the delete portion to work , what am i missing here. also is it possible/correct that the removeKeyValue function acquire the mutex lock only during the call to...
0
7676
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7932
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7442
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6001
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5347
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3473
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1905
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1032
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
729
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.