D
D-Dog
Hi,
I'm having some trouble overloading the '==' operator. I've snipped
irrelevant parts to demonstrate the problem. Perhaps someone can see
what I'm doing wrong.
I have a template class:
template<class T> class testFile {
private:
T data;
public:
bool operator==(testFile &val) {
return(data == val.data);
}
--------------------------------------------------------
The above works fine for any instance of testFile<{insert data type}>
However, when I do the following
class testFile2 {
private:
std::vector< testFile<{some-data-type}> > testThis;
public:
bool operator==(testFile2 &this_test) {
return(testThis == this_test.testThis);
}
}
I get the following compile error:
/usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/
bits/stl_algobase.h: In function `bool std::equal(_InputIterator1,
_InputIterator1, _InputIterator2) [with _InputIterator1 =
__gnu_cxx::__normal_iterator<const testFile<float>*,
std::vector<testFile<float>, std::allocator<testFile<float> > > >,
_InputIterator2 = __gnu_cxx::__normal_iterator<const testFile<float>*,
std::vector<testFile<float>, std::allocator<testFile<float> > > >]':
/usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/
bits/stl_vector.h:878: instantiated from `bool std:perator==(const
std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)[with _Tp =
testFile<float>, _Alloc = std::allocator<testFile<float> >]'
.../../src/include/../testFile2.h:24: instantiated from here
/usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/
bits/stl_algobase.h:691: error:no match for 'operator==' in
'(&__first1)->__gnu_cxx::__normal_iterator<_Iterator,
_Container>:perator* [with _Iterator = const testFile<float>*,
std::vector<testFile<float>, std::allocator<testFile<float> > >]()'
/../../src/include/../testFile.h:24: note: candidates are: bool
testFile<T>:perator==(testFile<T>&) [with T = float]
Apparently the vector is having some trouble in its operator locating
the proper template operator. Any idea how to handle this?
Thanks,
Dennis
I'm having some trouble overloading the '==' operator. I've snipped
irrelevant parts to demonstrate the problem. Perhaps someone can see
what I'm doing wrong.
I have a template class:
template<class T> class testFile {
private:
T data;
public:
bool operator==(testFile &val) {
return(data == val.data);
}
--------------------------------------------------------
The above works fine for any instance of testFile<{insert data type}>
However, when I do the following
class testFile2 {
private:
std::vector< testFile<{some-data-type}> > testThis;
public:
bool operator==(testFile2 &this_test) {
return(testThis == this_test.testThis);
}
}
I get the following compile error:
/usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/
bits/stl_algobase.h: In function `bool std::equal(_InputIterator1,
_InputIterator1, _InputIterator2) [with _InputIterator1 =
__gnu_cxx::__normal_iterator<const testFile<float>*,
std::vector<testFile<float>, std::allocator<testFile<float> > > >,
_InputIterator2 = __gnu_cxx::__normal_iterator<const testFile<float>*,
std::vector<testFile<float>, std::allocator<testFile<float> > > >]':
/usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/
bits/stl_vector.h:878: instantiated from `bool std:perator==(const
std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)[with _Tp =
testFile<float>, _Alloc = std::allocator<testFile<float> >]'
.../../src/include/../testFile2.h:24: instantiated from here
/usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/
bits/stl_algobase.h:691: error:no match for 'operator==' in
'(&__first1)->__gnu_cxx::__normal_iterator<_Iterator,
_Container>:perator* [with _Iterator = const testFile<float>*,
_Iterator = const testFile<float>*, _Container =_Container = std::vector said:__gnu_cxx::__normal_iterator<_Iterator, _Container>:perator* [with
std::vector<testFile<float>, std::allocator<testFile<float> > >]()'
/../../src/include/../testFile.h:24: note: candidates are: bool
testFile<T>:perator==(testFile<T>&) [with T = float]
Apparently the vector is having some trouble in its operator locating
the proper template operator. Any idea how to handle this?
Thanks,
Dennis