No Matching Function Call (dealing with addressing)

Hi.
I am trying to compile this program but I am getting the following compilation error several times for different functions, but all related to the one that im posting:
error: no matching function for call to 'Color3::set(Color3)'
note: candidates are: void Color3::set(Color3&)

where this code is being called as such:

Color3 clr;
SomeClass scn;
SomeOtherClass theRay;

clr.set( scn.shade(theRay) );


here is the function declaration for scn.shade(..):
color3 SomeClass:: shade(SomeOtherClass& ray){ .. }

This error makes no sense to me... anybody have ideas?
There are no 'const's being used anywhere, and the functino that clr.set(scn.shade(theRay)); is being called in is just a void doSomething() type function.

Thank you!!!
You have a function declared like this:

  void Color3::set( Color3& newcolor )

What this means is that you must have a Color3 variable somewhere to use it. For example:

1
2
Color3 c = scn.shade( theRay );
clr.set( c );

The reason is that the scn class returns a temporary variable -- which cannot be used as a mutable reference.

In order to fix this, you must fix the set color function:

  void Color3::set( const Color3& newcolor )

What this means is that you will not modify the argument to set() -- which is fair, since you are modifying clr and not the return value from shade().

Now you can use it as before:

  clr.set( scn.shade( theRay ) );

You can read up on this kind of stuff if you google around "c++ const correctness" and take a visit over to the C++FAQ-Lite.
http://www.parashift.com/c++-faq-lite/

Hope this helps.
That did the trick, I never looked at it ilke that.
Thank you for the great explanation ^_^
-Sean
Topic archived. No new replies allowed.