473,397 Members | 1,969 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,397 software developers and data experts.

A question of iterator

There are two programs , hamming.cpp and counting.cpp

In hamming.cpp:
I define a function
int distance(vector<int> v1, vector<int> v2);

We propate two vector to this function and return hamming distance

In counting.cpp:
I write~~
vector < vector < int> > L10;
........
for (int m5=0; m5 < L10.size(); m5++)
{
int d2 = distance ( L10[m5],temp);
We transfet L10[m5] and temp(type is: vector < int> ) to this
function distance
However, error occurs when I compile using Dev-C++
The error seems like it must use iterator.
How should I fix the program ?
Thanks a lot.

The error meaasge is as below~~
error occut in this row (int d2..)
In instantiation of `std::iterator_traits<std::vector<int,
std::allocator<int
':

31 C:\Dev-Cpp\code\counting.cpp instantiated from here
129 C:\Dev-Cpp\include\c++\3.4.2\bits\stl_iterator_base_types .h no
type
named `iterator_category' in `class std::vector<int,
std::allocator<int> >'
In stl_iterator_base_types.h, the content of 129 line is ~~
typedef typename _Iterator::iterator_category iterator_category;

Jul 28 '05 #1
2 1903
Sen-Lung Chen wrote:
There are two programs , hamming.cpp and counting.cpp

In hamming.cpp:
I define a function
int distance(vector<int> v1, vector<int> v2);
You'd be much better off passing those vectors by const refs:

int distance(vector<int> const& v1, vector<int> const& v2);
We propate two vector to this function and return hamming distance
What's "propate"?
In counting.cpp:
I write~~
vector < vector < int> > L10;
.......
for (int m5=0; m5 < L10.size(); m5++)
{
int d2 = distance ( L10[m5],temp);
We transfet L10[m5] and temp(type is: vector < int> ) to this
function distance
However, error occurs when I compile using Dev-C++
The error seems like it must use iterator.
How should I fix the program ?
It can be as simple as the naming conflict. Try renaming your function.
The compiler probably sees the 'std::distance' function first. Name your
function like 'my_distance' or 'get_distance'.
Thanks a lot.

The error meaasge is as below~~
error occut in this row (int d2..)
In instantiation of `std::iterator_traits<std::vector<int,
std::allocator<int
':


31 C:\Dev-Cpp\code\counting.cpp instantiated from here
129 C:\Dev-Cpp\include\c++\3.4.2\bits\stl_iterator_base_types .h no
type
named `iterator_category' in `class std::vector<int,
std::allocator<int> >'
In stl_iterator_base_types.h, the content of 129 line is ~~
typedef typename _Iterator::iterator_category iterator_category;


V
Jul 28 '05 #2
Thanks a lot~~
I have solve this problem.
I want to type " propagate"

Jul 29 '05 #3

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

Similar topics

38
by: Grant Edwards | last post by:
In an interview at http://acmqueue.com/modules.php?name=Content&pa=showpage&pid=273 Alan Kay said something I really liked, and I think it applies equally well to Python as well as the languages...
26
by: Michael Klatt | last post by:
I am trying to write an iterator for a std::set that allows the iterator target to be modified. Here is some relvant code: template <class Set> // Set is an instance of std::set<> class...
0
by: nick | last post by:
Hi, I need to manage a "layered" collection of objects, where each layer grows independently, e.g, o--+--+--+--+--+ 1st layer | o 2nd layer (empty) | o--+--+--+ 3rd...
14
by: shawnk | last post by:
I searched the net to see if other developers have been looking for a writable iterator in C#. I found much discussion and thus this post. Currently (C# 2) you can not pass ref and out arguments...
0
by: mailforpr | last post by:
Hi. Let me introduce an iterator to you, the so-called "Abstract Iterator" I developed the other day. I actually have no idea if there's another "Abstract Iterator" out there, as I have never...
21
by: T.A. | last post by:
I understand why it is not safe to inherit from STL containers, but I have found (in SGI STL documentation) that for example bidirectional_iterator class can be used to create your own iterator...
16
by: mailforpr | last post by:
How do I do that? The thing is, the only information I have about the iterator is the iterator itself. No container it is belonging to or anything. Like template<Iteratorvoid...
27
by: Steven D'Aprano | last post by:
I thought that an iterator was any object that follows the iterator protocol, that is, it has a next() method and an __iter__() method. But I'm having problems writing a class that acts as an...
4
by: mkborregaard | last post by:
Hi, I have the weirdest problem, and I can not see what is going wrong. I have made a 2d container class, and am implementing an iterator for that class. However, the ++ operator is behaving very...
2
by: Terry Reedy | last post by:
Luis Zarrabeitia wrote: Interesting observation. Iterators are intended for 'iterate through once and discard' usages. To zip a long sequence with several short sequences, either use...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
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...
0
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
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...

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.