"expected": ',', ','; ','} 'or' __attribute__ 'before' {'token' in the Struct member function

I am trying to compile code written by me with a more complex profile. This is the code I have:

/** * Vector class. * Common mathematical operations on vectors in R3. * * Written by Robert Osada, March 1999. **/ #ifndef __VECTOR_H__ #define __VECTOR_H__ /** * Vector3 **/ struct Vector3f { // coordinates float x, y, z; // norm float normSquared () { return x*x+y*y+z*z; } double norm () { return sqrt(normSquared()); } // boolean operators bool operator == (const Vector3f& v) const { return x==vx && y==vy && z==vz; } bool operator != (const Vector3f& v) const { return x!=vx || y!=vy || z!=vz; } // operators Vector3f operator + (const Vector3f &v) const { return Vector3f(x+vx, y+vy, z+vz); } Vector3f& operator += (const Vector3f &v) { x+=vx; y+=vy; z+=vz; return *this; } Vector3f operator - () const { return Vector3f(-x, -y, -z); } Vector3f operator - (const Vector3f &v) const { return Vector3f(xv.x, yv.y, zv.z); } Vector3f& operator -= (const Vector3f &v) { x-=vx; y-=vy; z-=vz; return *this; } Vector3f operator * (float s) const { return Vector3f(x*s, y*s, z*s); } Vector3f& operator *= (float s) { x*=s; y*=s; z*=s; return *this; } Vector3f operator / (float s) const { assert(s); return (*this)* (1/s); } Vector3f& operator /= (float s) { assert(s); return (*this)*=(1/s); } // create a vector Vector3f (float x_=0, float y_=0, float z_=0) : x(x_), y(y_), z(z_) {}; // set coordinates void set (float x_, float y_, float z_) { x=x_; y=y_; z=z_; } }; inline float Dot (const Vector3f& l, const Vector3f r) { return lx*rx + ly*ry + lz*rz; } // cross product inline Vector3f Cross (const Vector3f& l, const Vector3f& r) { return Vector3f( ly*rz - lz*ry, lz*rx - lx*rz, lx*ry - ly*rx ); } #include "Misc.h" /* inline Vector3f Min (const Vector3f &l, const Vector3f &r) { return Vector3f(Min(lx,rx), Min(ly,ry), Min(lz,rz)); } inline Vector3f Max (const Vector3f &l, const Vector3f &r) { return Vector3f(Max(lx,rx), Max(ly,ry), Max(lz,rz)); } */ #endif 

and I get an error on the line that defines normSquared (). It seems to give an error, regardless of which method is first included in the structure. Are there any suggestions?

+4
source share
3 answers

Are you trying to compile the C compiler? If you try to compile your C ++ code with only C compiler, I think you will get this type of message.

+1
source

Your built-in functions skip their class class specifications: None Vector3f:: .

For instance:

 inline float Vector3f::Dot (const Vector3f& l, const Vector3f r) { // ... } 
+1
source

I could not resolve the compiler errors, so I just rewrote the methods as static inline methods. Having pulled everything out of the structure, I managed to get it to work. I simply dropped operator overloads, because they were not actually used anywhere in the project. (I said it is too complicated).

Thanks to all who responded!

0
source

All Articles