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

Overloaded operators ++(), - - ()problem

P: n/a
N4M
Dear,
I have problems with overloaded operators ++() and --(). MSVC++ 6.0
compiler gives errors, one is shown as below:
"
c:\data\c++\mygraphs\graph.h(182) : error C2555: 'CGraphNodeIter::++'
: overriding virtual function differs from 'CGraphNodeIterI::++' only
by return type or calling convention
c:\data\c++\mygraphs\graph.h(141) : see declaration of
'CGraphNodeIterI'
"

Codes are as below (I give a full code, sorry if it is somewhat long):

// Class:CGraphNodeIterI
class CGraphNodeIterI //abstract class to interface : COMPLETE &&
MINIMAL (S. Meyer, Item 18)
{
public:
typedef ::TGraphNode TNode;// int
public:
// Constructors, Deconstructors
CGraphNodeIterI() {}
CGraphNodeIterI(const CGraphNodeIterI& rNode) {}
//~CGraphNodeIterI();
virtual ~CGraphNodeIterI() {}
virtual CGraphNodeIterI& operator=(const CGraphNodeIterI& rNode) {}
// Operators
virtual TNode operator *() const = 0;
virtual CGraphNodeIterI& operator ++() = 0; //Prefix
virtual CGraphNodeIterI& operator --() = 0; //Prefix
virtual bool operator ==(const CGraphNodeIterI& rNode) = 0;
virtual bool operator !=(const CGraphNodeIterI& rNode) = 0;

};
//----------------------------------------------------------------------------
// Node iterator
class CGraphNodeIter: public CGraphNodeIterI //implementation
{
public:
typedef ::TGraphNode TNode;//int
private:
TNode m_nNode;
public:
// Constructors, Deconstructors
CGraphNodeIter(): m_nNode(TNode()) {}
explicit CGraphNodeIter(TNode rNode): m_nNode(rNode) {}
CGraphNodeIter(const CGraphNodeIter& rNode): m_nNode(rNode.m_nNode)
{}
~CGraphNodeIter();

CGraphNodeIter& operator=(const CGraphNodeIter& rNode) {
if (this != & rNode) m_nNode = rNode.m_nNode;
return *this;
}
// Operators
TNode operator *() const { return m_nNode; };
CGraphNodeIter& operator ++() { ++m_nNode; return *this; } //Prefix
CGraphNodeIter& operator --() { ASSURE(m_nNode >=
1);--m_nNode; return *this;} //Prefix
bool operator ==(const CGraphNodeIter& rNode) { return m_nNode ==
rNode.m_nNode;}
bool operator !=(const CGraphNodeIter& rNode) { return !(*this ==
rNode);}

};

Could you take a look and tell me where I make mistake?
Thanks a lot.
Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

"N4M" <dn******@yahoo.com> schrieb im Newsbeitrag
news:6e**************************@posting.google.c om...
Dear,
I have problems with overloaded operators ++() and --(). MSVC++ 6.0
compiler gives errors, one is shown as below:
"
c:\data\c++\mygraphs\graph.h(182) : error C2555: 'CGraphNodeIter::++' : overriding virtual function differs from 'CGraphNodeIterI::++' only by return type or calling convention
c:\data\c++\mygraphs\graph.h(141) : see declaration of
'CGraphNodeIterI'
virtual CGraphNodeIterI& operator ++() = 0; //Prefix
CGraphNodeIter& operator ++() { ++m_nNode; return *this; } //Prefix


See the difference of your return type:
CGraphNodeIterI&
CGraphNodeIter&
--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}

________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com
Jul 22 '05 #2

P: n/a
N4M
> See the difference of your return type:
CGraphNodeIterI&
CGraphNodeIter& Yeah, the point that MSVC6 does not support covariant return types!
________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com

Jul 22 '05 #3

P: n/a
Gernot Frisch wrote:

"N4M" <dn******@yahoo.com> schrieb im Newsbeitrag
news:6e**************************@posting.google.c om...
Dear,
I have problems with overloaded operators ++() and --(). MSVC++ 6.0
compiler gives errors, one is shown as below:
"
c:\data\c++\mygraphs\graph.h(182) : error C2555:

'CGraphNodeIter::++'
: overriding virtual function differs from 'CGraphNodeIterI::++'

only
by return type or calling convention
c:\data\c++\mygraphs\graph.h(141) : see declaration of
'CGraphNodeIterI'

virtual CGraphNodeIterI& operator ++() = 0; //Prefix
CGraphNodeIter& operator ++() { ++m_nNode; return *this; } //Prefix


See the difference of your return type:
CGraphNodeIterI&
CGraphNodeIter&


I hope you didn't mean to say that was an invalid way to override a
virtual function. As the OP pointed out himself, the problem was
that MSVC++ 6.0 didn't support it.

To the OP: take a close look at your operators == and !=. You are hiding
them in the derived class, not overriding.

Denis
Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.