A question of iterator

S

Sen-Lung Chen

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;
 
V

Victor Bazarov

Sen-Lung Chen said:
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 said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,142
Latest member
DewittMill
Top