Re: C++ Overloaded pure virtual operators (170 Views)
Reply
Occasional Visitor
Hai Nguyen Dennis Kavan
Posts: 1
Registered: ‎11-30-1998
Message 1 of 2 (170 Views)

C++ Overloaded pure virtual operators

Hello all,

I cannot figure out why the 10.2 compiler complains....

class IFile
{
public:

virtual IFile& operator << ( IFile& f, const unsigned int u) const =
0;
};

with the following error...am I losing my mind???


Error 317: "dennis1.hxx", line 7 # Overloaded operator "IFile
&IFile::operator
<<(IFile &,unsigned int) const" expected to take 1 arguments.
virtual IFile& operator << ( IFile& f, const unsigned int u)
const = 0;

Any thoughts??????

Please use plain text.
Honored Contributor
RikTytgat
Posts: 432
Registered: ‎07-03-2000
Message 2 of 2 (170 Views)

Re: C++ Overloaded pure virtual operators

Hi,

This is normal. You should believe what the compiler tells you: the left shift operator expects only 1 parameter. You can't just choose a random signature for parameter overloading. Try:

virtual IFile& operator << ( unsigned int u);

Some more remarks:
1. It doesn't make sense to write "const unsigned int". This is redundant information. If you simply write "unsigned int", it's const enough.

2. I shouldn't define this function const. Were you planning not to alter the "this" object in the implementation of your operator? Then what would you return (as a reference)? Not a local variable I hope?

bye,
Rik
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation