C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 03-25-2009, 06:33 AM   #1
Registered User
 
Join Date: Mar 2009
Posts: 37
getting error while building the same on linux "no match for operator"

below is the snippet of code:
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
error:

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   Reply With Quote
Old 03-25-2009, 06:59 AM   #2
Guest
 
Sebastiani's Avatar
 
Join Date: Aug 2001
Posts: 5,034
Maybe because 'Int' is undefined (eg: should be 'int')?
Sebastiani is offline   Reply With Quote
Old 03-25-2009, 07:07 AM   #3
Registered User
 
Join Date: Mar 2009
Posts: 37
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   Reply With Quote
Old 03-25-2009, 07:29 AM   #4
The larch
 
Join Date: May 2006
Posts: 3,222
Your iterator supports Iterator - int, but not Iterator - Iterator (to get the distance).
__________________
I might be wrong.

Quote:
Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
Quoted more than 1000 times (I hope).
anon is offline   Reply With Quote
Old 03-25-2009, 07:41 AM   #5
Guest
 
Sebastiani's Avatar
 
Join Date: Aug 2001
Posts: 5,034
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...
      */
    }
At any rate, that would mean you have somehow confused the STL (possibly because of the 'public iterator_traits<typename C::iterator>' derivation. Can you post a full example that we can compile?
Sebastiani is offline   Reply With Quote
Old 03-25-2009, 10:50 AM   #6
The larch
 
Join Date: May 2006
Posts: 3,222
Quote:
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').
And what do you think std::distance will call internally (with random access iterators)?

No idea why find would need the distance, though...
__________________
I might be wrong.

Quote:
Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
Quoted more than 1000 times (I hope).
anon is offline   Reply With Quote
Old 03-26-2009, 02:38 AM   #7
Registered User
 
Join Date: Mar 2009
Posts: 37
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   Reply With Quote
Old 03-26-2009, 05:45 AM   #8
The larch
 
Join Date: May 2006
Posts: 3,222
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';
    }
}
There are a couple of problems:

Code:
class poly_iterator 
#if _MSC_VER>=1300 // VC7
    : public iterator_traits<typename C::iterator>
#endif
The typedefs that you get by inheriting from iterator_traits are required from an iterator when they are to be used with STL algorithms. It's not just some VC7 thing.

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;
    }
The implementation of std::find apparently is doing some loop unrolling for random access iterators and needs the distance for that.

And one convenience thing:

Code:
poly_iterator<std::vector<int>, int> first(v.begin()), last(v.end()), it;
What is the point of repeating the int as if this argument could ever be anything but the containers value type?

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;
(Eventually, the template argument could be the Iterator type, so that this adapter would also work for plain pointers.)
__________________
I might be wrong.

Quote:
Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
Quoted more than 1000 times (I hope).

Last edited by anon; 03-26-2009 at 05:57 AM.
anon is offline   Reply With Quote
Old 03-30-2009, 02:36 AM   #9
Registered User
 
Join Date: Mar 2009
Posts: 37
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;
}
error:

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   Reply With Quote
Old 03-30-2009, 06:37 PM   #10
Guest
 
Sebastiani's Avatar
 
Join Date: Aug 2001
Posts: 5,034
Your question has already been answered. Hint: reread anon's post...
Sebastiani is offline   Reply With Quote
Reply

Tags
code

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 05:19 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22