473,468 Members | 1,307 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

map/set iterators incompatible

5 New Member
I have defined the following in the header file(mappingItem.h).
typedef std::map <int, std::string> mappingItem;
mappingItemType m1;
mappingItemType m2;

And in mappingItem.cpp i m getting error in the below mention line.
std::stringstream source_val;
std::stringstream target_val;
source_val << m1.size();
target_val << m2.size();
if ( m1.size() == m2.size() )
{
/*I m getting a run time error here..*/
mappingItem::iterator source = m1.begin();
mappingItem::iterator target = m2.begin();

for( ; source != m1.end() && source != m2.end() ;source++, target++ )
{
/*code is here*/
}
Can anybody suggest??? please help....
Feb 17 '12 #1

✓ answered by weaknessforcats

If this is in your header file:

Expand|Select|Wrap|Line Numbers
  1. typedef std::map <int, std::string> mappingItem;
  2.  mappingItemType m1;
  3.  mappingItemType m2;
  4.  
Then a) thrre is no mappintItemType so there is no m1 and b) everytime you incude this header an instance of m1 and m2 will be created.

It is a hard fule that you do not put executable code in your header files. You only put declarations, so the typedef is appropriate.
Create yout m1 and m2 in a .cpp that is art of the build.

Fix these problems and then repost your code.

Also, you might read this: http://bytes.com/topic/c/insights/73...obal-variables

5 7044
weaknessforcats
9,208 Recognized Expert Moderator Expert
If this is in your header file:

Expand|Select|Wrap|Line Numbers
  1. typedef std::map <int, std::string> mappingItem;
  2.  mappingItemType m1;
  3.  mappingItemType m2;
  4.  
Then a) thrre is no mappintItemType so there is no m1 and b) everytime you incude this header an instance of m1 and m2 will be created.

It is a hard fule that you do not put executable code in your header files. You only put declarations, so the typedef is appropriate.
Create yout m1 and m2 in a .cpp that is art of the build.

Fix these problems and then repost your code.

Also, you might read this: http://bytes.com/topic/c/insights/73...obal-variables
Feb 17 '12 #2
lakshmiyc
5 New Member
I have changed it.. But still i m getting RunTime error..
Feb 17 '12 #3
lakshmiyc
5 New Member
typedef std::map <int, std::string> mappingItemType;

And in mappingItem.cpp i m getting error in the below mention line.
mappingItemType m1;
mappingItemType m2;

std::stringstream source_val;
std::stringstream target_val;
source_val << m1.size();
target_val << m2.size();
if ( m1.size() == m2.size() )
{
/*I m getting a run time error here..*/
mappingItemType::iterator source = m1.begin();
mappingItemType::iterator target = m2.begin();

for( ; source != m1.end() && source != m2.end() ;source++, target++ )
{
/*code is here*/
}
Feb 17 '12 #4
lakshmiyc
5 New Member
can anybody suggest?? :(:(
Feb 17 '12 #5
Banfa
9,065 Recognized Expert Moderator Expert
source != m2.end() source is an iterator into m1, there is no point comparing it to m2.end() it will never be equal did you mean target != m2.end() ?
Feb 17 '12 #6

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

Similar topics

10
by: Steven Bethard | last post by:
So, as I understand it, in Python 3000, zip will basically be replaced with izip, meaning that instead of returning a list, it will return an iterator. This is great for situations like: zip(*)...
18
by: deancoo | last post by:
I have gotten into the habit of often using copy along with an insert iterator. There are scenarios where I process quite a lot of data this way. Can someone give me a general feel as to how much...
24
by: Lasse Vågsæther Karlsen | last post by:
I need to merge several sources of values into one stream of values. All of the sources are sorted already and I need to retrieve the values from them all in sorted order. In other words: s1 = ...
4
by: kalita | last post by:
Hi All, typedef std::list<int> Cont; void f(Cont &c1, Cont &c2) { Cont::iterator it = c1.begin(); c1.swap(c2); it == c2.begin(); // is this ill formed? }
6
by: Shiraz | last post by:
Me and my colleagues have been working on a problem since yesterday and can’t seem to find a solution to it. It relates in a good measure to iterators and the way we’re using them in our...
3
by: ngaloppo | last post by:
Hi, compiling a program with the code blurb below causes a runtime error ("Expression: vector iterators incompatible") due to the debug iterators in VC++ 8. The error happens in the...
2
by: ma740988 | last post by:
typedef std::vector < std::complex < double > > complex_vec_type; // option1 int main() { complex_vec_type cc ( 24000 ); complex_vec_type dd ( &cc, &cc ); } versus
90
by: John Salerno | last post by:
I'm a little confused. Why doesn't s evaluate to True in the first part, but it does in the second? Is the first statement something different? False print 'hi' hi Thanks.
19
by: fungus | last post by:
I mentioned earlier to day that I was moving some code from VC++6 to VC++2005 and having trouble with the new iterators. There's all sorts of problems cropping up in the code thanks to this...
2
by: Michael Jenning | last post by:
Hi, I'm getting a "vector iterators incompatible" error. Here's my code: vector<term>::const_iterator first; vector<term>::const_iterator last; getSegment(smallest, i, first, last); ...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.