I'm following along some sample code, but I'm getting an error from it that I don't know how to fix properly. I'm getting an error passing *this as a reference. Here's the relevant code:
//ShadeRec.h
class World;
class ShadeRec
{
public:
World& w;
ShadeRec(World& wr)
}
ShadeRec::ShadeRec(World& wr) : w(wr) {}
//World.h
#include "ShadeRec.h"
#include "Ray.h"
class World
{
public:
World();
ShadeRec hit_bare_bones_objects(const Ray& ray) const;
}
ShadeRec World::hit_bare_bones_objects(const Ray& ray) const
{
ShadeRec sr(*this);
//Do stuff with sr
return sr;
}
The error is happening in hit_bare_bones_objects where I declare ShadeRec sr(*this); The error is:
1> error C2664: 'ShadeRec::ShadeRec(const ShadeRec &)' : cannot convert argument 1 from 'const World' to 'World &'
1> Conversion loses qualifiers
What is the correct way to do this?