472,958 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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.ucSeatLetter ='A';
memset((void*)&pdata,0,sizeof(PedData));
pdata.nPortClass = 1;
pdata.tSeatRowCols = sdata;
data[sdata] = pdata;

while compiling this code the following error are occurs.

Compiling...
DemoOfDatatStructures.cpp
E:\testprjs\testit\DemoOfDatatStructures\DemoOfDat atStructures.cpp(79)
: warning C4786:
'std::reverse_bidirectional_iterator<std::_Tree<_S eatRowCols,std::pair<_SeatRowCols
const
,_PedData>,std::map<_SeatRowCols,_PedData,std::les s<_SeatRowCols>,std::
allocator<_PedData>
::_Kfn,std::less<_SeatRowCols>,std::allocator<_Pe dData> >::iterator,std::pair<_SeatRowCols const ,_PedData>,std::pair<_SeatRowCols const ,_PedData> &,std::pair<_SeatRowCols const ,_PedData> *,int>' : identifier was truncated to '255' characters in the debug information
E:\testprjs\testit\DemoOfDatatStructures\DemoOfDat atStructures.cpp(79)
: warning C4786:
'std::reverse_bidirectional_iterator<std::_Tree<_S eatRowCols,std::pair<_SeatRowCols
const
,_PedData>,std::map<_SeatRowCols,_PedData,std::les s<_SeatRowCols>,std::
allocator<_PedData>::_Kfn,std::less<_SeatRowCols>,std::allocator<_Pe dData> >::const_iterator,std::pair<_SeatRowCols const ,_PedData>,std::pair<_SeatRowCols const ,_PedData> const &,std::pair<_SeatRowCols const ,_PedData> const *,int>' : identifier was truncated to '255' characters in the debug information
E:\testprjs\testit\DemoOfDatatStructures\DemoOfDat atStructures.cpp(79)
: warning C4786:
'std::pair<std::_Tree<_SeatRowCols,std::pair<_Seat RowCols const
,_PedData>,std::map<_SeatRowCols,_PedData,std::les s<_SeatRowCols>,std::allocator<_PedData>::_Kf n,std::less<_SeatRowCols>,std::allocator<_PedData>::iterator,std::_Tree<_SeatRowCols,std::pair<_Sea tRowCols const ,_PedData>,std::map<_SeatRowCols,_PedData,std::les s<_SeatRowCols>,std::allocator<_PedData> >::_Kfn,std::less<_SeatRowCols>,std::alloc ator<_PedData> >::iterator>' : identifier was truncated to '255'
characters in the debug information
E:\testprjs\testit\DemoOfDatatStructures\DemoOfDat atStructures.cpp(79)
: warning C4786:
'std::pair<std::_Tree<_SeatRowCols,std::pair<_Seat RowCols const
,_PedData>,std::map<_SeatRowCols,_PedData,std::les s<_SeatRowCols>,std::allocator<_PedData>::_Kf n,std::less<_SeatRowCols>,std::allocator<_PedData>::const_iterator,std::_Tree<_SeatRowCols,std::pai r<_SeatRowCols const ,_PedData>,std::map<_SeatRowCols,_PedData,std::les s<_SeatRowCols>,std::allocator<_PedData> >::_Kfn,std::less<_SeatRowCols>,std:

:allocator<_PedData> >::const_iterator>' : identifier was truncated to
'255' characters in the debug information
e:\program files\microsoft visual studio\vc98\include\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\include\functional(86) : while compiling class-template
member function 'bool __thiscall std::less<struct
_SeatRowCols>::operator ()(const struct _SeatRowCols &,const struct
_SeatRowCols &) const
'
e:\program files\microsoft visual studio\vc98\include\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,_Pr,_A> &' from 'const struct _SeatRowCols'
e:\program files\microsoft visual
studio\vc98\include\functional(86) : while compiling class-template
member function 'bool __thiscall std::less<struct
_SeatRowCols>::operator ()(const struct _SeatRowCols &,const struct
_SeatRowCols &) const
'
e:\program files\microsoft visual studio\vc98\include\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\include\functional(86) : while compiling class-template
member function 'bool __thiscall std::less<struct
_SeatRowCols>::operator ()(const struct _SeatRowCols &,const struct
_SeatRowCols &) const
'
e:\program files\microsoft visual studio\vc98\include\functional(86) :
error C2784: 'bool __cdecl std::operator <(const class
std::reverse_iterator<_RI,_Ty,_Rt,_Pt,_D> &,const class
std::reverse_iterator<_RI,_Ty,_Rt,_Pt,_D> &)' : could not deduce te
mplate argument for 'const class
std::reverse_iterator<_RI,_Ty,_Rt,_Pt,_D> &' from 'const struct
_SeatRowCols'
e:\program files\microsoft visual
studio\vc98\include\functional(86) : while compiling class-template
member function 'bool __thiscall std::less<struct
_SeatRowCols>::operator ()(const struct _SeatRowCols &,const struct
_SeatRowCols &) const
'
e:\program files\microsoft visual studio\vc98\include\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\include\functional(86) : while compiling class-template
member function 'bool __thiscall std::less<struct
_SeatRowCols>::operator ()(const struct _SeatRowCols &,const struct
_SeatRowCols &) const
'
e:\program files\microsoft visual studio\vc98\include\functional(86) :
error C2784: 'bool __cdecl operator <(_Interface *,class
_com_ptr_t<_InterfacePtr> &)' : could not deduce template argument for
' *' from 'const struct _SeatRowCols'
e:\program files\microsoft visual
studio\vc98\include\functional(86) : while compiling class-template
member function 'bool __thiscall std::less<struct
_SeatRowCols>::operator ()(const struct _SeatRowCols &,const struct
_SeatRowCols &) const
'
e:\program files\microsoft visual studio\vc98\include\functional(86) :
error C2784: 'bool __cdecl operator <(int,class _com_ptr_t<_Interface>
&)' : could not deduce template argument for 'overloaded function type'
from 'overloaded function type'
e:\program files\microsoft visual
studio\vc98\include\functional(86) : while compiling class-template
member function 'bool __thiscall std::less<struct
_SeatRowCols>::operator ()(const struct _SeatRowCols &,const struct
_SeatRowCols &) const
'
e:\program files\microsoft visual studio\vc98\include\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\include\functional(86) : while compiling class-template
member function 'bool __thiscall std::less<struct
_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 9577

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()(const _SeatRowCols &left, const _SeatRowCols
&right) const
{

// define your comparsion conditions for the "SeatRowCols"
// 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*******@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.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
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()(const _SeatRowCols &left, const _SeatRowCols
&right) const
{

// define your comparsion conditions for the "SeatRowCols"
// 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 7 '06 #11
Now it is working. For this I overload the < operator in SeatRowCols
structure.
Thanx Earl Purple, and Jim Langston for their valuable explaination
on need of overlaoding < operator in data structures while using them
as a mapkey. Thanx to all other contributors.

Kamaraj

Jan 9 '06 #12

pa**********@gmail.com wrote:
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.
No they don't. operator< is compiler-defined for primitive types only.
std::string also has operator< defined as part of the standard library.
bool operator()(const _SeatRowCols &left, const _SeatRowCols
&right) const
{
Wrong operator. You want to overload

bool operator<( ()(const _SeatRowCols &left, const _SeatRowCols &right) const


as a non-member function (you made yours a member).

You can (less preferably) overload it as a member

bool SeatRowCols::operator<( const SeatRowCols & rhs ) const;

noting that the function as well as the parameter should be const,.

Jan 9 '06 #13

Jim Langston wrote:
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.


To be pedantic, they use std::less< T >() to sort unless an alternative
predicate is supplied. And std::less< T > uses operator< unless it is
specialised to do otherwise. Specialising the template to is therefore
one alternative although I wouldn't recommend it. (You'd expect
std::less to call operator< wouldn't you).

Jan 9 '06 #14

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

Similar topics

5
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,...
3
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>); ...
2
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...
0
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...
2
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,...
1
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...
4
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,...
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...
2
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...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.