Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
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.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
Languages and Scripting
Showing results for 
Search instead for 
Did you mean: 

C++ Overloaded pure virtual operators

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

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

with the following I losing my mind???

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

Any thoughts??????

Honored Contributor

Re: C++ Overloaded pure virtual operators


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?