N
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.
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.