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. 3 1683
"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
> 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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Andy Jarrell |
last post by:
I'm trying to inherit from a specific class that has an overloaded operator. The problem I'm getting is that certain
overloaded operators don't seem to come with the inheritance. For example:
...
|
by: Brad Eck |
last post by:
"The only operators that cannot be overloaded
are :: (scope resolution), . (member selection), and .* (member
selection through pointer to function). Quoting from Stroustrup's 3rd
edition of _The...
|
by: masood.iqbal |
last post by:
Please help me with this doubt that I have regarding overloaded
operators. Sometimes they are member functions and sometimes they are
friends (e.g. see the code snippet from Stroustrup, Second...
|
by: maadhuu |
last post by:
hi
i wasnt to know the answer for the following.
now ,u can overload all the operators which are basically determined at
runtime (coz' of whch operators like sizeof())cannot be overloaded.
now...
|
by: Riku Jarvinen |
last post by:
Hello everyone,
I have a logging class which writes program outputs to the logfile. The
class works fine as long as only C++ native data types are considered. The
problem is that I have a...
|
by: Alex Zhitlenok |
last post by:
Hi,
My question is how to resolve in C# ambiguous overloaded operators?
Let say, I have two unrelated classes A and B, each one implements
overloaded operator + with the first parameter of type...
|
by: Jack Daly |
last post by:
I've inherited some code which uses an undocumented feature of a
third-party vendor's library. Essentially, this vendor has kept the
details of an interface struct secret, but we can pass a pointer...
|
by: olanglois |
last post by:
Hi,
I am trying to derive a new class that will add new functions but no
new data members and the base class has overloaded operators
(+,-,+=,-=,etc...) returning either (Base &) or (const Base)...
|
by: raylopez99 |
last post by:
I need an example of a managed overloaded assignment operator for a
reference class, so I can equate two classes A1 and A2, say called
ARefClass, in this manner: A1=A2;. For some strange reason...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| | |