By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,120 Members | 1,275 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,120 IT Pros & Developers. It's quick & easy.

A question of iterator

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
Thanks a lot~~
I have solve this problem.
I want to type " propagate"

Jul 29 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.