![]() |
| |||||||
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 |
| Registered User Join Date: Mar 2009
Posts: 35
| getting error while building the same on linux "no match for operator" same is compiling over AIX and windows, but I need to compile the same on linux and deliver it today but getting errors. I highlighted the error statement Code: #ifndef _POLY_ITERATOR_
#define _POLY_ITERATOR_
#include <iterator>
#ifndef HPUX11
using namespace std;
#endif //HPUX11
#include <iterator>
#ifndef LIN
using namespace std;
#endif //HPUX11
template<class C, typename T>
class poly_iterator
#if _MSC_VER>=1300 // VC7
: public iterator_traits<typename C::iterator>
#endif
{
private:
// typedef poly_iterator<C,T> _Self;
protected:
typedef typename C::iterator I;
//!< regular iterator of the underlying container
I i;
//! mimic inheritage from the regular iterator
//! because we cannot simply derive from it since
// some iterators are regular pointers
public:
operator I&()
{
return (I&)i;
}
//!<needed to use poly_iterator in algorithms transparently
public:
poly_iterator<C,T>() {};
poly_iterator<C,T>(const I& p):i(p) {};
//!< construction form const_poly_iterator
T& operator*() {return (T&)*i;}
T* operator->() {return (T*)&*i;}
public: // compatibility with I iterator
poly_iterator<C,T>& operator++() {++i; return *this;}
poly_iterator<C,T>& operator--() {--i; return *this;}
poly_iterator<C,T> operator+(const Int count)
{
I temp = i;
temp += count;
return poly_iterator<C,T>(temp);
}
poly_iterator<C,T> operator-(const Int count)
{
I temp = i;
temp -= count;
return poly_iterator<C,T>(temp);
}
poly_iterator<C,T>& operator++(Int)
{
i++;
return *this;
}
poly_iterator<C,T>& operator--(Int)
{
i--;
return *this;
}
bool operator<(const poly_iterator<C,T>& other) const
{
return i < other.i;
}
bool operator<(const I& other) const
{
return i < other;
}
bool operator<=(const poly_iterator<C,T>& other) const
{
return i <= other.i;
}
bool operator<=(const I& other) const
{
return i <= other;
}
bool operator>(const poly_iterator<C,T>& other) const
{
return i > other.i;
}
bool operator>(const I& other) const
{
return i > other;
}
bool operator>=(const poly_iterator<C,T>& other) const
{
return i >= other.i;
}
bool operator>=(const I& other) const
{
return i >= other;
}
bool operator==(const I& other) const
{
return i==other;
}
bool operator!=(const I& other) const
{
return i!=other;
}
bool operator==(const poly_iterator<C,T>& other) const
{
return i==other.i;
}
bool operator!=(const poly_iterator<C,T>& other) const
{
return i!=other.i;
}
};
#endif // _POLY_ITERATOR_
#endif
LiteRouteStop*>, _Tp = AbstractRouteStop*]â /apps/lcom/Engines/2009Env/Consolidator/include/LiteRoute.hpp:688: instantiated from here /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:204: error: no match for âoperator-â in â__last - __firstâ /apps/lcom/Engines/2009Env/Consolidator/include/Utility.hpp:259: note: candidates are: poly_iterator<C, T> poly_iterator<C, T>: perator-(Int) [with C = std::vector<AbstractRouteStop*, std::allocator<AbstractRouteStop*> >, T = LiteRouteStop*]/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_bvector.h:182: note: ptrdiff_t std: perator-(const std::_Bit_iterator_base&, const std::_Bit_iterator_base&)/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:225: error: no match for âoperator-â in â__last - __firstâ /apps/lcom/Engines/2009Env/Consolidator/include/Utility.hpp:259: note: candidates are: poly_iterator<C, T> poly_iterator<C, T>: perator-(Int) [with C = std::vector<AbstractRouteStop*, std::allocator<AbstractRouteStop*> >, T = LiteRouteStop*]/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_bvector.h:182: note: ptrdiff_t std: perator-(const std::_Bit_iterator_base&, const std::_Bit_iterator_base&)/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h: In function â_RandomAccessIterator std::__find(_RandomAccessIterator, _RandomAccessIterator, const _Tp&, std::random_access_iterator_tag) [with _RandomAccessIterator = poly_iterator<std::vector<AbstractRouteStop*, std::allocator<AbstractRouteStop*> >, LiteRouteStop*>, _Tp = LiteRouteStop*]â: /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:316: instantiated from â_InputIterator std::find(_InputIterator, _InputIterator, const _Tp&) [with _InputIterator = poly_iterator<std::vector<AbstractRouteStop*, std::allocator<AbstractRouteStop*> >, LiteRouteStop*>, _Tp = LiteRouteStop*]â /apps/lcom/Engines/2009Env/Consolidator/include/LiteRoute.hpp:692: instantiated from here /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:204: error: no match for âoperator-â in â__last - __firstâ /apps/lcom/Engines/2009Env/Consolidator/include/Utility.hpp:259: note: candidates are: poly_iterator<C, T> poly_iterator<C, T>: perator-(Int) [with C = std::vector<AbstractRouteStop*, std::allocator<AbstractRouteStop*> >, T = LiteRouteStop*]/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_bvector.h:182: note: ptrdiff_t std: perator-(const std::_Bit_iterator_base&, const std::_Bit_iterator_base&)/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:225: error: no match for âoperator-â in â__last - __firstâ /apps/lcom/Engines/2009Env/Consolidator/include/Utility.hpp:259: note: candidates are: poly_iterator<C, T> poly_iterator<C, T>: perator-(Int) [with C = std::vector<AbstractRouteStop*, std::allocator<AbstractRouteStop*> >, T = LiteRouteStop*]/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_bvector.h:182: note: ptrdiff_t std: perator-(const std::_Bit_iterator_base&, const std::_Bit_iterator_base&)/apps/lcom/Engines/2009Env/Consolidator/include/Order.hpp: At global scope: /apps/lcom/Engines/2009Env/Consolidator/include/Order.hpp:761: warning: inline function âvirtual Lfloat Order::_GetSizeValueForConsCode(std::string)â used but never defined make[2]: *** [libConsCore.a(LiteEngine.o)] Error 1 Thanks in Advance. Please help!! Vaibhav |
| vaibhavs17 is offline | |
| | #2 |
| Guest Join Date: Aug 2001
Posts: 4,923
| Maybe because 'Int' is undefined (eg: should be 'int')? |
| Sebastiani is offline | |
| | #3 |
| Registered User Join Date: Mar 2009
Posts: 35
| that Int is user defined... i.e. internally defined as 'int' typedef int Int; inline LiteRouteStopListIterator LiteRoute::_PositionStop(LiteRouteStop* stop) { LiteRouteStopListIterator stopIterator = /*line 688*/ find(GetRouteStopListBegin(), GetRouteStopListEnd(), (AbstractRouteStop*)stop); while (stopIterator != GetRouteStopListEnd() && !stop->IsSameAsStop(*(*(stopIterator)))) { stopIterator = find(++stopIterator, GetRouteStopListEnd(), stop); } return stopIterator; } typedef typename C::iterator I; Last edited by vaibhavs17; 03-25-2009 at 07:21 AM. |
| vaibhavs17 is offline | |
| | #4 | |
| The larch Join Date: May 2006
Posts: 3,086
| Your iterator supports Iterator - int, but not Iterator - Iterator (to get the distance).
__________________ I might be wrong. Quote:
| |
| anon is offline | |
| | #5 |
| Guest Join Date: Aug 2001
Posts: 4,923
| Strange - it could it be that 'find' is trying to subtract two poly_iterators (ie: to calculate the distance between them?). Stl containers do that with pointers (ie: arrays), of course, but never classes (it would internally call 'std::distance'). Try defining this just to see if it compiles: Code: Int operator-(poly_iterator<C,T> const& rhs)
{
/*
Just to see if it compiles...
*/
}
|
| Sebastiani is offline | |
| | #6 | ||
| The larch Join Date: May 2006
Posts: 3,086
| Quote:
No idea why find would need the distance, though...
__________________ I might be wrong. Quote:
| ||
| anon is offline | |
| | #7 |
| Registered User Join Date: Mar 2009
Posts: 35
| Sabestini, Its a big source code, anyway I have tried your option also regarding change of argument data type to poly iterator kindof but still facing error but of different type.. i tried this: poly_iterator<C,T> operator-(const poly_iterator<C,T>& other) { I temp =i; poly_iterator<C,T> temp =(temp -(other.i)); return temp; } LiteEngine.cpp:3517: warning: converting to âIntâ from âLfloatâ /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h: In function â_RandomAccessIterator std::__find(_RandomAccessIterator, _RandomAccessIterator, const _Tp&, std::random_access_iterator_tag) [with _RandomAccessIterator = poly_iterator<std::vector<AbstractRouteStop*, std::allocator<AbstractRouteStop*> >, LiteRouteStop*>, _Tp = AbstractRouteStop*]â: /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:316: instantiated from â_InputIterator std::find(_InputIterator, _InputIterator, const _Tp&) [with _InputIterator = poly_iterator<std::vector<AbstractRouteStop*, std::allocator<AbstractRouteStop*> >, LiteRouteStop*>, _Tp = AbstractRouteStop*]â /apps/lcom/Engines/2009Env/Consolidator/include/LiteRoute.hpp:688: instantiated from here /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:204: error: no match for âoperator>>â in â__last.poly_iterator<C, T>: perator- [with C = std::vector<AbstractRouteStop*, std::allocator<AbstractRouteStop*> >, T = LiteRouteStop*](((const poly_iterator<std::vector<AbstractRouteStop*, std::allocator<AbstractRouteStop*> >, LiteRouteStop*>&)((const poly_iterator<std::vector<AbstractRouteStop*, std::allocator<AbstractRouteStop*> >, LiteRouteStop*>*)(& __first)))) >> 2â/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:225: error: switch quantity not an integer /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h: In function â_RandomAccessIterator std::__find(_RandomAccessIterator, _RandomAccessIterator, const _Tp&, std::random_access_iterator_tag) [with _RandomAccessIterator = poly_iterator<std::vector<AbstractRouteStop*, std::allocator<AbstractRouteStop*> >, LiteRouteStop*>, _Tp = LiteRouteStop*]â: /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:316: instantiated from â_InputIterator std::find(_InputIterator, _InputIterator, const _Tp&) [with _InputIterator = poly_iterator<std::vector<AbstractRouteStop*, std::allocator<AbstractRouteStop*> >, LiteRouteStop*>, _Tp = LiteRouteStop*]â /apps/lcom/Engines/2009Env/Consolidator/include/LiteRoute.hpp:692: instantiated from here /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:204: error: no match for âoperator>>â in â__last.poly_iterator<C, T>: perator- [with C = std::vector<AbstractRouteStop*, std::allocator<AbstractRouteStop*> >, T = LiteRouteStop*](((const poly_iterator<std::vector<AbstractRouteStop*, std::allocator<AbstractRouteStop*> >, LiteRouteStop*>&)((const poly_iterator<std::vector<AbstractRouteStop*, std::allocator<AbstractRouteStop*> >, LiteRouteStop*>*)(& __first)))) >> 2â/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:225: error: switch quantity not an integer /apps/lcom/Engines/2009Env/Consolidator/include/Order.hpp: At global scope: /apps/lcom/Engines/2009Env/Consolidator/include/Order.hpp:761: warning: inline function âvirtual Lfloat Order::_GetSizeValueForConsCode(std::string)â used but never defined make[2]: *** [libConsCore.a(LiteEngine.o)] Error 1 |
| vaibhavs17 is offline | |
| | #8 | |
| The larch Join Date: May 2006
Posts: 3,086
| It ain't that hard to produce a sample program that calls std::find with poly_iterators: Code: int main()
{
std::vector<int> v(10);
v[4] = 42;
poly_iterator<std::vector<int>, int> first(v.begin()), last(v.end()), it;
it = std::find(first, last, 42);
if (it != last) {
std::cout << *it << '\n';
}
}
Code: class poly_iterator
#if _MSC_VER>=1300 // VC7
: public iterator_traits<typename C::iterator>
#endif
And then, operator- should return the distance of two iterators: that's an integral type: Code: typename I::difference_type operator-(const poly_iterator<C,T>& other)
{
//I temp =i;
//poly_iterator<C,T> temp =(temp -(other.i));
//return temp;
return i - other.i;
}
And one convenience thing: Code: poly_iterator<std::vector<int>, int> first(v.begin()), last(v.end()), it; Instead you could remove the second template argument (BTW inside the templated class declaration you can refer to the class without keeping saying <C, T>), and perhaps as a quick fix throw in a typedef: Code: template<class C>
class poly_iterator : public iterator_traits<typename C::iterator>
{
private:
// typedef poly_iterator<C,T> _Self;
protected:
typedef typename C::iterator I;
typedef typename I::value_type T;
__________________ I might be wrong. Quote:
Last edited by anon; 03-26-2009 at 05:57 AM. | |
| anon is offline | |
| | #9 |
| Registered User Join Date: Mar 2009
Posts: 35
| iterator find is not working on linux but same is working on windows Please help! I have created a sample program, I am able build on windows but linux but on linux getting below error TEST.HPP Code: #include<iostream>
#include <iterator>
#include <vector>
typedef int Int;
using namespace std;
template<class C, typename T>
class poly_iterator : public iterator_traits<typename C::iterator>
{
private:
// typedef poly_iterator<C,T> _Self;
protected:
typedef typename C::iterator I;
//!< regular iterator of the underlying container
I i;
//! mimic inheritage from the regular iterator
//! because we cannot simply derive from it since
// some iterators are regular pointers
public:
operator I&()
{
return (I&)i;
}
//!<needed to use poly_iterator in algorithms transparently
public:
poly_iterator<C,T>() {};
poly_iterator<C,T>(const I& p):i(p) {};
//!< construction form const_poly_iterator
T& operator*() {return (T&)*i;}
T* operator->() {return (T*)&*i;}
public: // compatibility with I iterator
poly_iterator<C,T>& operator++() {++i; return *this;}
poly_iterator<C,T>& operator--() {--i; return *this;}
poly_iterator<C,T> operator+(const Int count)
{
I temp = i;
temp += count;
return poly_iterator<C,T>(temp);
}
poly_iterator<C,T> operator-(const Int count)
{
I temp = i;
temp -= count;
return poly_iterator<C,T>(temp);
}
poly_iterator<C,T>& operator++(Int)
{
i++;
return *this;
}
poly_iterator<C,T>& operator--(Int)
{
i--;
return *this;
}
bool operator<(const poly_iterator<C,T>& other) const
{
return i < other.i;
}
bool operator<(const I& other) const
{
return i < other;
}
bool operator<=(const poly_iterator<C,T>& other) const
{
return i <= other.i;
}
bool operator<=(const I& other) const
{
return i <= other;
}
bool operator>(const poly_iterator<C,T>& other) const
{
return i > other.i;
}
bool operator>(const I& other) const
{
return i > other;
}
bool operator>=(const poly_iterator<C,T>& other) const
{
return i >= other.i;
}
bool operator>=(const I& other) const
{
return i >= other;
}
bool operator==(const I& other) const
{
return i==other;
}
bool operator!=(const I& other) const
{
return i!=other;
}
bool operator==(const poly_iterator<C,T>& other) const
{
return i==other.i;
}
bool operator!=(const poly_iterator<C,T>& other) const
{
return i!=other.i;
}
};
TEST.CPP
//#include "stdafx.h"
// iterator_traits.cpp
// compile with: /EHsc
#include <iostream>
#include <iterator>
#include <vector>
#include <list>
#include <algorithm>
using namespace std;
#include "test.hpp"
int main()
{
vector<int> v(10);
v[4] = 42;
poly_iterator<vector<int>, int> it;
poly_iterator<vector<int>, int> first(v.begin());
poly_iterator<vector<int>, int> last(v.end());
it = find(first, last, 42);
if (it != last) {
cout << *it << '\n';
}
return 0;
}
epuser@VOPTENG01 ~/Consolidator/vaibhav $> g++ test.cpp -o test.exe /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h: In function â_RandomAccessIterator std::__find(_RandomAccessIterator, _RandomAccessIterator, const _Tp&, std::random_access_iterator_tag) [with _RandomAccessIterator = poly_iterator<std::vector<int, std::allocator<int> >, int>, _Tp = int]â: /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:316: instantiated from â_InputIterator std::find(_InputIterator, _InputIterator, const _Tp&) [with _InputIterator = poly_iterator<std::vector<int, std::allocator<int> >, int>, _Tp = int]â test.cpp:20: instantiated from here /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:204: error: no match for âoperator-â in â__last - __firstâ test.hpp:50: note: candidates are: poly_iterator<C, T> poly_iterator<C, T>: perator-(Int) [with C = std::vector<int, std::allocator<int> >, T = int]/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_bvector.h:182: note: ptrdiff_t std: perator-(const std::_Bit_iterator_base&, const std::_Bit_iterator_base&)/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:316: instantiated from â_InputIterator std::find(_InputIterator, _InputIterator, const _Tp&) [with _InputIterator = poly_iterator<std::vector<int, std::allocator<int> >, int>, _Tp = int]â test.cpp:20: instantiated from here /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:225: error: no match for âoperator-â in â__last - __firstâ test.hpp:50: note: candidates are: poly_iterator<C, T> poly_iterator<C, T>: perator-(Int) [with C = std::vector<int, std::allocator<int> >, T = int]/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_bvector.h:182: note: ptrdiff_t std: perator-(const std::_Bit_iterator_base&, const std::_Bit_iterator_base&) |
| vaibhavs17 is offline | |
| | #10 |
| Guest Join Date: Aug 2001
Posts: 4,923
| Your question has already been answered. Hint: reread anon's post... |
| Sebastiani is offline | |
![]() |
| Tags |
| code |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Why Linux, for the average user? | Hunter2 | General Discussions | 32 | 07-07-2006 02:36 PM |
| Dabbling with Linux. | Hunter2 | Tech Board | 21 | 04-21-2005 04:17 PM |
| installing linux for the first time | Micko | Tech Board | 9 | 12-06-2004 05:15 AM |
| Linux Linux why Linux?? | afreedboy | Tech Board | 146 | 01-21-2004 06:27 PM |