programming the neat way
I''m trying to put everything in .cpp files with .h headers. i have the #include "quaternion.h" in my matrix.h and #include "matrix.h" in my quaternion.h and the #ifndef #define #endif stuff in the top of my headers. why does it still give these errors?
Thanx,
Marty
--------------------Configuration: NukeM2 - Win32 Debug--------------------
Compiling...
matrix.cpp
c:\program files\microsoft visual studio\myprojects\objloader\nukem2\quaternion.h(84) : error C2146: syntax error : missing '';'' before identifier ''QuatToMatrix''
c:\program files\microsoft visual studio\myprojects\objloader\nukem2\quaternion.h(84) : error C2501: ''t_matrix'' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\myprojects\objloader\nukem2\quaternion.h(84) : fatal error C1004: unexpected end of file found
quaternion.cpp
c:\program files\microsoft visual studio\myprojects\objloader\nukem2\matrix.h(70) : error C2146: syntax error : missing '';'' before identifier ''MatrixToQuat''
c:\program files\microsoft visual studio\myprojects\objloader\nukem2\matrix.h(70) : error C2501: ''t_quat'' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\myprojects\objloader\nukem2\matrix.h(70) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
NukeM2.exe - 6 error(s), 0 warning(s)
_____ /____ /|| | || MtY | ||_____|/Marty
You know we REALLY cant tell without seing your code but aperantly your missing simicolons and such;
OH AND USUALLY! unexpected end of file MEANS THAT THERES NOT AN EXTRA EMPTY LINE AT THE END OF THE .H FILE!
[All The Web] [Google!] [ Look I DONT Follow Trends ]
[edited by - DerAngeD on January 31, 2004 5:02:04 PM]
OH AND USUALLY! unexpected end of file MEANS THAT THERES NOT AN EXTRA EMPTY LINE AT THE END OF THE .H FILE!
[All The Web] [Google!] [ Look I DONT Follow Trends ]
[edited by - DerAngeD on January 31, 2004 5:02:04 PM]
here''s the code for quaternion.h
and for matrix.h
// quaternion.h#ifndef _QUATERNION_H#define _QUATERNION_H#include <math.h>#include "vector.h"#include "matrix.h"//////////////////////////////////////////////////////////////////////// Types//////////////////////////////////////////////////////////////////////typedef struct t_quat{ t_quat() { X=0; Y=0; Z=0; W=1; } t_quat(float x, float y, float z, float w) { X = x; Y = y; Z = z; W = w; } t_quat operator + (t_quat AddQuat) { return (t_quat(X + AddQuat.X, Y + AddQuat.Y, Z + AddQuat.Z, W + AddQuat.W)); } t_quat operator - (t_quat SubQuat) { return (t_quat(X - SubQuat.X, Y - SubQuat.Y, Z - SubQuat.Z, W - SubQuat.W)); } t_quat operator * (float scalar) { return (t_quat(X * scalar, Y * scalar, Z * scalar, W * scalar)); } t_quat operator * (t_quat q) { t_quat temp; temp.W = W * q.W - X * q.X - Y * q.Y - Z * q.Z; temp.X = W * q.X + X * q.W + Y * q.Z - Z * q.Y; temp.Y = W * q.Y + Y * q.W + Z * q.X - X * q.Z; temp.Z = W * q.Z + Z * q.W + X * q.Y - Y * q.X; return (temp / (float)sqrt(temp.X * temp.X + temp.Y * temp.Y + temp.Z * temp.Z + temp.W * temp.W)); } t_quat operator * (t_vec3 v) { t_quat V (v.X, v.Y, v.Z, 0); t_quat temp; temp.W = - X * V.X - Y * V.Y - Z * V.Z; temp.X = W * V.X + Y * V.Z - Z * V.Y; temp.Y = W * V.Y + Z * V.X - X * V.Z; temp.Z = W * V.Z + X * V.Y - Y * V.X; return temp; } t_quat operator / (float scalar) { return (t_quat(X / scalar, Y / scalar, Z / scalar, W / scalar)); } float X, Y, Z, W;}t_quat;//////////////////////////////////////////////////////////////////////// Classes////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Functions//////////////////////////////////////////////////////////////////////float QuatLength(t_quat q);void NormalizeQuat(t_quat &q);t_quat QuadNormalize(t_quat q);t_quat MultQuat(t_quat q1, t_quat q2);t_quat ConjugateQuat(t_quat q);t_quat EulerToQuat(float xrot, float yrot, float zrot);t_matrix QuatToMatrix(t_quat q);void RotateVector(t_vec3 &V, t_quat q);#endif
and for matrix.h
//matrix.h#ifndef _MATRIX_H#define _MATRIX_H#include "quaternion.h"//////////////////////////////////////////////////////////////////////// Types//////////////////////////////////////////////////////////////////////typedef struct t_matrix{ t_matrix () { for (int i = 0; i < 16; i++) { if (i%5) {values[i] = 0;} else {values[i] = 1;} } } t_matrix operator + (t_matrix AddMatrix) { t_matrix temp; for (int i = 0; i < 16; i++) {temp.values[i] = values[i] + AddMatrix.values[i];} return temp; } t_matrix operator - (t_matrix SubMatrix) { t_matrix temp; for (int i = 0; i < 16; i++) {temp.values[i] = values[i] - SubMatrix.values[i];} return temp; } t_matrix operator * (t_matrix m) { t_matrix temp; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; i++) { temp.values[i*4+j] = values[i*4+0] * m.values[0+j] + values[i*4+1] * m.values[4+j] + values[i*4+2] * m.values[8+j] + values[i*4+3] * m.values[12+j]; } } return temp; } float values[16]; }t_matrix;//////////////////////////////////////////////////////////////////////// Classes////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Functions//////////////////////////////////////////////////////////////////////int GetGLMatrix(t_matrix &m);int SetGLMatrix(t_matrix m);t_quat MatrixToQuat(t_matrix m);#endif
_____ /____ /|| | || MtY | ||_____|/Marty
To me, it appears to be:
1) you forgot the semicolon after the class definition
class SomeClass
{
};
2) you have the problem of the chicken and egg
try:
hope that helps !
Matt
1) you forgot the semicolon after the class definition
class SomeClass
{
};
2) you have the problem of the chicken and egg
try:
// quaternion.hclass CMatrix; // or whatever name your matrix class haveclass CQuaternion{ // class definition goes here};// matrix.hclass CQuaternion;class CMatrix{ // class definition goes here};
hope that helps !
Matt
Matt
The problem is that you''re cross-including. When matrix.h includes quaterion.h, and quaternion.h includes matrix.h, you''re in an infinitely recursive cycle. Your header guards prevent the "infinite" part, but you still won''t have all the declarations where you want.
You need to forward declare the classes you use as arguments for functions. This means that you can''t have an inline function in quaternion which takes a matrix, AND have an inline function in matrix which takes a quaternion, at the same time, without some extra trickery.
The common thing to do is to just forward declare classes and methods in headers, and actually define the methods in .cpp files.
You need to forward declare the classes you use as arguments for functions. This means that you can''t have an inline function in quaternion which takes a matrix, AND have an inline function in matrix which takes a quaternion, at the same time, without some extra trickery.
The common thing to do is to just forward declare classes and methods in headers, and actually define the methods in .cpp files.
// matrix.h
#if !defined( matrix_h )
#define matrix_h
class Quaternion;
class Matrix {
public:
Matrix( Quaternion const & init );
};
#endif
// quaternion.h
#if !defined( quaternion_h )
#define quaternion_h
class Matrix;
class Quaternion {
public:
Quaternion( Matrix const & init );
};
#endif // quaternion_h
// matrix.cpp
#include "matrix.h"
#include "quaternion.h"
Matrix::Matrix( Quaternion const & q )
{
...
}
// quaternion.cpp
#include "quaternion.h"
#include "matrix.h"
Quaternion::Quaternion( Matrix const & m )
{
...
}<br><br>To support inlines, you have to split your include file in two parts, forward declare the referenced classes and declare your class, THEN include the other file, THEN define the inlines (outside the class declaration). The other file does the same thing; it forward-declares what it needs, declares the class, THEN includes the first file (which won''t be included if it''s already seen), THEN defines the inlines (outside the actual class declaration). </pre>
enum Bool { True, False, FileNotFound };
quote:
Original post by DerAnged
OH AND USUALLY! unexpected end of file MEANS THAT THERES NOT AN EXTRA EMPTY LINE AT THE END OF THE .H FILE!
Really? I believe it means that there's a open brace or something without a closing brace. What difference would an extra empty line make? :/
[edited by - porthios on January 31, 2004 5:12:20 PM]
hplus0603: I use the #ifndef in the headers, so i think that''s the same u told me to do, right?
lemurion: I don''t have any classes in the headers (yet) just typedef''s and they all have the ; at the end...
still don''t get this
thanx anyways,
Marty
lemurion: I don''t have any classes in the headers (yet) just typedef''s and they all have the ; at the end...
still don''t get this

thanx anyways,
Marty
_____ /____ /|| | || MtY | ||_____|/Marty
quote:
Original post by DerAnged
OH AND USUALLY! unexpected end of file MEANS THAT THERES NOT AN EXTRA EMPTY LINE AT THE END OF THE .H FILE!
Nope. Unexpected end of file usually happen when the compiler doesn't parse the source correctly.
What you say has a message like "Extra line missing at the end of file".
[edited by - owl on January 31, 2004 5:30:15 PM]
[size="2"]I like the Walrus best.
I think the real problem is the names of your classes. You should try "Matrix" and "Quaterion" :-)
________________________________________________Chris McGuirkLead Programmer - Axiom 3D EngineC# gaming, the way of the future!http://www.axiom3d.org
Ok, I think you don''t get me. I''ll try to explain it again.
I have lots of .cpp files that all have a .h header file.
this is what they look like:
OtherType is a type defined in otherheader.h
in otherheader.h there are functions that return SomeType.
So both headers need to include the other.
because of the #ifndef there shouldn''t be any problems, right?
so why do I still get these errors?
I have lots of .cpp files that all have a .h header file.
this is what they look like:
#ifndef _HEADERNAME_H // it doesn''t get defined twice#define _HEADERNAME_H#include "otherheader.h"typedef struct SomeType{...}SomeStruct; // notice the ; !OtherType SomeFunction(); // notice the ; again#endif
OtherType is a type defined in otherheader.h
in otherheader.h there are functions that return SomeType.
So both headers need to include the other.
because of the #ifndef there shouldn''t be any problems, right?
so why do I still get these errors?
_____ /____ /|| | || MtY | ||_____|/Marty
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement