no match for 'operator!=' in ...

M

Mr Dyl

I'm having a few issues porting Windows code to Linux (VS.Net 2003 to
GCC 4.0.1). So this probably has something to do with VS not catching
non-compliant code. I'd like to simplify this problem, but I'm not
really sure what the issue is. I appologize in advance, as this
doesn't give you much to go on. Basically, I want to compare my own
iterators with stl vector iterators. I've written the operator== and
operator!= functions to do this (actually, they're methods... I
couldn't figure out how to make them static functions due to a host of
other issues we probably don't need to get into). I'm hoping that
maybe somebody can spot a clue in the error message. Here's the
problem code:

CHAIN_CONTAINER::const_iterator stl_itEnd =
my_itChain->getOwner()->getChains().end();

if (my_itChain != stl_itEnd) // OK
do_something();

fi (my_itChain != my_itChain->getOwner()->getChains().end()) // GCC
complains
do_something();


Here's the error message I'm getting on the fourth line:


ContainerChild.cpp: In member function 'ContainerChild::pjt_iterator
ContainerChild::beginPJT(Container<A, B, C, D>::c_iterator&)':
ContainerChild.cpp:133: error: no match for 'operator!=' in 'itC !=
(+(+ itC)->Container<T1, T2, T3, T4>::c_iterator::eek:perator-> [with T1 =
A, T2 = B, T3 = C, T4 =
D]()->C::getOwner()->B::<anonymous>.BParent::getChains())->std::vector<_Tp,
_Alloc>::end [with _Tp = CParent*, _Alloc =
std::allocator<CParent*>]()'
.../common/Container.h:223: note: candidates are: bool Container<T1, T2,
T3, T4>::c_iterator::eek:perator!=(const Container<T1, T2, T3,
T4>::c_iterator&) [with T1 = A, T2 = B, T3 = C, T4 = D]
.../common/Container.h:225: note: bool Container<T1, T2,
T3, T4>::c_iterator::eek:perator!=(__gnu_cxx::__normal_iterator<CParent*
const*, std::vector<CParent*, std::allocator<CParent*> > >&) [with T1 =
A, T2 = B, T3 = C, T4 = D]



Thanks in advance!
 
J

Jonathan Mcdougall

Mr said:
I'm having a few issues porting Windows code to Linux (VS.Net 2003 to
GCC 4.0.1). So this probably has something to do with VS not catching
non-compliant code. I'd like to simplify this problem, but I'm not
really sure what the issue is. I appologize in advance, as this
doesn't give you much to go on. Basically, I want to compare my own
iterators with stl vector iterators. I've written the operator== and
operator!= functions to do this (actually, they're methods... I
couldn't figure out how to make them static functions due to a host of
other issues we probably don't need to get into). I'm hoping that
maybe somebody can spot a clue in the error message. Here's the
problem code:

CHAIN_CONTAINER::const_iterator stl_itEnd =
my_itChain->getOwner()->getChains().end();

if (my_itChain != stl_itEnd) // OK
do_something();

fi (my_itChain != my_itChain->getOwner()->getChains().end()) // GCC
complains
do_something();


Here's the error message I'm getting on the fourth line:


ContainerChild.cpp: In member function 'ContainerChild::pjt_iterator
ContainerChild::beginPJT(Container<A, B, C, D>::c_iterator&)':
ContainerChild.cpp:133: error: no match for 'operator!=' in 'itC !=
(+(+ itC)->Container<T1, T2, T3, T4>::c_iterator::eek:perator-> [with T1 =
A, T2 = B, T3 = C, T4 =
D]()->C::getOwner()->B::<anonymous>.BParent::getChains())->std::vector<_Tp,
_Alloc>::end [with _Tp = CParent*, _Alloc =
std::allocator<CParent*>]()'
../common/Container.h:223: note: candidates are: bool Container<T1, T2,
T3, T4>::c_iterator::eek:perator!=(const Container<T1, T2, T3,
T4>::c_iterator&) [with T1 = A, T2 = B, T3 = C, T4 = D]
../common/Container.h:225: note: bool Container<T1, T2,
T3, T4>::c_iterator::eek:perator!=(__gnu_cxx::__normal_iterator<CParent*
const*, std::vector<CParent*, std::allocator<CParent*> > >&) [with T1 =
A, T2 = B, T3 = C, T4 = D]

Whew. Could you tell us:

1) the exact type (const or not) of my_itChain
2) the exact type (const or not) of
my_itChain->getOwner()->getChains().end()
3) the declaration of your operator!=().


Jonathan
 
M

Mr Dyl

Whew is right! It turned out to be quite the red herring. I figured
out (sort of) what was going on while typing out a reply to your post.
My operator== and operator!= RHS arguments weren't const references.
Ooops. Anyway, if you're interested below are the answers to your
questions. I put the const error in CAPS.

I also noticed that I should have rewritten the code snippet to make
it a tad easier to read in relation to the error message. Here it is
again:

std::vector<C*>::const_iterator stl_itEnd =
my_itC->getOwner()->getCs().end();
if (my_itC != stl_itEnd) // OK
do_something();

if (my_itC != my_itC->getOwner()->getCs().end()) // GCC complains
do_something();

Your questions...

1) The type for 'my_itC' is a nested class declared inside Container.
See below.
2) As it appears above (ie. std::vector<C*>::const_iterator )
3) See below as well.

template<typename T1, typename T2, typename T3, typename T4>
class Container {
public:
class a_iterator {
public:
bool operator==(CONST std::vector<A*>::const_iterator& itRHS)
{return(m_itA == itRHS);}
bool operator!=(CONST std::vector<A*>::const_iterator& itRHS)
{return(!(*this == itRHS));}
protected:
std::vector<A*>::iterator m_itA;
...
};

class b_iterator : a_iterator {
public:
bool operator==(CONST std::vector<B*>::const_iterator& itRHS)
{return(m_itB == itRHS);}
bool operator!=(CONST std::vector<B*>::const_iterator& itRHS)
{return(!(*this == itRHS));}
protected:
std::vector<B*>::iterator m_itB;
...
};

class c_iterator : b_iterator {
public:
bool operator==(CONST std::vector<C*>::const_iterator& itRHS)
{return(m_itC == itRHS);}
bool operator!=(CONST std::vector<C*>::const_iterator& itRHS)
{return(!(*this == itRHS));}
protected:
std::vector<C*>::iterator m_itC;
...
};

class d_iterator : c_iterator {
public:
bool operator==(CONST std::vector<D*>::const_iterator& itRHS)
{return(m_itD == itRHS);}
bool operator!=(CONST std::vector<D*>::const_iterator& itRHS)
{return(!(*this == itRHS));}
protected:
std::vector<D*>::iterator m_itD;
...
};
...
};

class ContainerChild : public Container <A, B, C, D> {
};
 

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

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top