This topic is 2305 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

So I am getting this error while trying to over load the cin operator.

I keep getting this error " No operator ">>" Matches these operands"

But this is how all of my examples look. Can anyone be kind enough to point this one out for me?

Here's the base code:
 //date.h class Date { int month, day, year; Public: friend istream& operator>>(istream&,const Date&); } 

 //date.cpp #include"date.h" #include<iostream> using namespace std; istream& operator>>(istream& strm,const Date& d) { cout<<"Enter Day: "; strm >> d.day; return strm; }; 

Share on other sites
Okay, I soon as I posted this I figured it out. the const keyword. Okay Problem solved!

Share on other sites

 istream& operator>>(istream& strm,const Date& d) { cout<<"Enter Day: "; // * strm >> d.day; return strm; }; 

* Ooof. Don't do that (inside the extraction operator, that is). Remember that streams are generic; you could be reading form something other than cin. You wouldn't want a whole spam of "Enter Day: " messages to appear in the console if you were reading Dates from a file, would you?