Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

C++ Overloaded pure virtual operators

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 REPLIES
Highlighted
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