constant reference

Hello forum,

I am having problem with the constant reference issue. The line that gives error is as follows:

 
 Ray *r = new Ray(is.mPosition,importanceSampleVector);


The parameter that i am sending it to the ray constructor are created in the function scope as follows:

 
 Vector3D importanceSampleVector = sampleCosine(is,pdf);


I am not sure why is it causing so. Please check the following constructor:

1
2
3
4
5
6
7
   Ray(const Point3D& o, const Vector3D& d, float mint=0.001f, float maxt=INF)
      : orig(o), minT(mint), maxT(maxt)
   {
      //the following calculates the direction, inverse direction
      //and flag for the inverse direction
      setDirection(d);
   }



And the error i getting is :

1
2
3
4
5
6
7
pathtracer.cpp: In member function ‘Color PathTracer::trace(const Ray&)’:
pathtracer.cpp:187: error: call of overloaded ‘Ray(Point3D&, Vector3D&)’ is ambiguous
ray.h:62: note: candidates are: Ray::Ray(const Point3D&, const Vector3D&, const Ray::Differential&, const Ray::Differential&, float, float)
ray.h:52: note:                 Ray::Ray(const Point3D&, const Vector3D&, float, float)
make: *** [pathtracer.o] Error 1
make: *** Waiting for unfinished jobs....



Any hint to get around this problem?


Regards
Sajjad
¿Did you put default values in the other constructor too?
Hi again,

Yes , as a matter of fact i do . Let take a look at the whole class struture as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public:
   /// Default Constructor. The position and direction are left
   /// un-initialized, but the time is set to 0 and infinity respectively.
   Ray() : minT(0.001f), maxT(INF) { }
   
   Ray(const Point3D& o, const Vector3D& d, float mint=0.001f, float maxt=INF)
      : orig(o), minT(mint), maxT(maxt)
   {
      //the following calculates the direction, inverse direction
      //and flag for the inverse direction
      setDirection(d);
   }
   
   /// Constructor initializing the ray's origin and direction,
   /// and optionally the time parameters. The direction is normalized.
   Ray(const Point3D& o, const Vector3D& d, const Differential& dp = Differential(), const Differential& dd = Differential(), float mint=0.001f, float maxt=INF)
      : orig(o), dp(dp), dd(dd), minT(mint), maxT(maxt)
   {
      setDirection(d);
   }
And how do you expect that the compiler will decide which constructor to call.
If there are 2 constructors(or any functions) that have the same name and if you removed all or some of the default arguments they would be the same(same types of arguments, same numbe rof arguments) are ambiguos. I recommend something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public:
   /// Default Constructor. The position and direction are left
   /// un-initialized, but the time is set to 0 and infinity respectively.
   Ray() : minT(0.001f), maxT(INF) { }
   
   Ray(const Point3D& o, const Vector3D& d, const Differential& d1 = Differential(), const Differential& d2 = Differential(), float mint=0.001f, float maxt=INF, string choose)
      : orig(o), minT(mint), maxT(maxt)
   {
      if (choose=="dif")
     {
           dp=Differential(d1);
           dd=Differential(d2);
           }
      setDirection(d);
   }
   

the choose string can be "withdif" or "withoutdif", so you can choose which to use.
Topic archived. No new replies allowed.