This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Assignment Operator Bug


Mactavish <mdtabishalam@gmail.com> writes:
> I have compiled this code in MS Visual C++ Express 2008 and it works as
> it should be but when i compile this code in Mingw as a part of GCC ver
> 4.4.1-2 the input() function should return a temporary object to 'ob'
> object and invoke the assignment operator '=' but it doesn't and it
> shows me error :"no match for 'operator=' in 'ob=input()()'   "

This is the wrong mailing list for this question (the list is for gcc
development).  A better list would be <gcc-help@gcc.gnu.org> or maybe
the comp.lang.c++ newsgroup.

As to your problem, I think it's a bug in your program (and a bug in
VC++ that it accepts it).  Later versions of gcc give a more
explanatory error message, which make the reason more obvious:

   $ g++-4.6 -c s.cc
   s.cc: In function âint main()â:
   s.cc:63:14: error: no match for âoperator=â in âob = input()()â
   s.cc:63:14: note: candidate is:
   s.cc:46:8: note: sample sample::operator=(sample&)
   s.cc:46:8: note:   no known conversion for argument 1 from âsampleâ to âsample& {aka sample&}â

Temporary objects can't be passed as non-const references.

You can fix it by changing the argument type of sample::operator= to
be "const sample &" instead of "sample &".

-Miles

-- 
One of the lessons of history is that nothing is often a good thing to
do, and always a clever thing to say.  -- Will Durant


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]