 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Sen-Lung Chen Guest
|
Posted: Thu Jul 28, 2005 3:50 pm Post subject: 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
std::allocator
| Quote: | ':
31 C:Dev-Cppcodecounting.cpp instantiated from here |
129 C:Dev-Cppincludec++3.4.2bitsstl_iterator_base_types.h no
type
named `iterator_category' in `class std::vector
std::allocator'
In stl_iterator_base_types.h, the content of 129 line is ~~
typedef typename _Iterator::iterator_category iterator_category;
|
|
| Back to top |
|
 |
Victor Bazarov Guest
|
Posted: Thu Jul 28, 2005 4:07 pm Post subject: Re: A question of iterator |
|
|
Sen-Lung Chen wrote:
| Quote: | 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);
| Quote: | We propate two vector to this function and return hamming distance
|
What's "propate"?
| Quote: | 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'.
| Quote: | Thanks a lot.
The error meaasge is as below~~
error occut in this row (int d2..)
In instantiation of `std::iterator_traits<std::vector
std::allocator
':
31 C:Dev-Cppcodecounting.cpp instantiated from here
129 C:Dev-Cppincludec++3.4.2bitsstl_iterator_base_types.h no
type
named `iterator_category' in `class std::vector
std::allocator'
In stl_iterator_base_types.h, the content of 129 line is ~~
typedef typename _Iterator::iterator_category iterator_category;
|
V
|
|
| Back to top |
|
 |
Sen-Lung Chen Guest
|
Posted: Fri Jul 29, 2005 6:34 pm Post subject: Re: A question of iterator |
|
|
Thanks a lot~~
I have solve this problem.
I want to type " propagate"
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|