This is the mail archive of the 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 <> 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 <> 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 In function âint main()â: error: no match for âoperator=â in âob = input()()â note: candidate is: note: sample sample::operator=(sample&) 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 &".


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]