Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No known conversion for argument from type to type&

I have a function that overloads operator= in class 'ssm'

ssm& operator=(ssm& rhs);

Later I use an ssm object (itsSSM) as a member of another class(mt3dset). I use the following declaration to initialize that member in the constructor.

itsSSM= ssm();

But I am getting an error:

error: no match for ‘operator=’ in ‘((mt3dSet*)this)->mt3dSet::itsSSM = ssm()’

error: no known conversion for argument 1 from ‘ssm’ to ‘ssm&’

Is it a problem with compiler (g++ 4.7)? (Please ask for more information if required)

like image 513
George Avatar asked Aug 12 '13 17:08

George


Video Answer


1 Answers

Nope, it's not a problem with the compiler. You can't bind a temporary to a non-const reference. Note that Visual C++ has an extension to allow this non-standard feature.

Just change your copy assignent to take its argument as const:

ssm& operator=(const ssm& rhs);

like image 107
Mark B Avatar answered Sep 28 '22 14:09

Mark B