a function definition is not allowed here before '{' token

I am getting the error title, of this method

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <cmath>
#include "RayTracer.h"

inline bool RayTracer::intersect (const Sphere &sphere, const Ray &ray, float &t) { //ERROR HERE!
    vector ray-sphere = sphere.center - ray.start;
    float projection = ray-sphere * ray.dir;
    if (projection<0)
      return false;
    float smallerSide_squared = ray_sphere*ray_sphere - projection*projection;
    if (smallerSide_squared>sphere.radius_squared)
      return false;
    float t =  sqrt (sphere.radius_squared - smallerSide*smallerSide);
    float t0 = projection - t;
    float t1 = projection + t;
    if ((t0 > 0.1f) && (t0 < t))
    {
        t = t0;
        retvalue = true;
    }
    if ((t1 > 0.1f) && (t1 < t))
    {
        t = t1;
        retvalue = true;
    }
    return retvalue;
}


#include "GeometricObjects.h"
#include "Image.h"

class RayTracer {
  public:
    bool intersect (Sphere &sphere, Ray &ray, float &t);
    void trace     (Image &image);
};





I checked the internet and the same error warning happened when there is a mismatch of the number of opened/closed {} but I cannot see this here. What can be the error?
Thanks for any help.
You may be missing a } in the header file instead.
Where? I putted the code of the header at the end. As can be seen, I only open one { , the class one, that I also close.

Edit: Figured out the error, was not paying attention to the header files included in the "RayTracer.h" header. In one of them there was the single opened {
Last edited on
it might be in GeometricObjects.h or Image.h
Do you have a semi-colon ; at the end of RayTracer.h?
Topic archived. No new replies allowed.