By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,376 Members | 1,557 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,376 IT Pros & Developers. It's quick & easy.

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

P: n/a
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::operator-> [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::operator!=(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::operator!=(__gnu_cxx::__normal_it erator<CParent*
const*, std::vector<CParent*, std::allocator<CParent*> > >&) [with T1 =
A, T2 = B, T3 = C, T4 = D]

Thanks in advance!

Dec 28 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Mr Dyl wrote:
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::operator-> [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::operator!=(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::operator!=(__gnu_cxx::__normal_it erator<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

Dec 28 '05 #2

P: n/a
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> {
};

Dec 29 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.