Simpler Navigation for Servers and Operating Systems
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

C++ Overloaded pure virtual operators

Highlighted
Hai Nguyen Dennis Kavan
Occasional Visitor

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??????

1 REPLY
RikTytgat
Honored Contributor

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