Static library and namespaces

Started by
12 comments, last by Zakwayda 15 years, 5 months ago
You're making the same mistake again. NEVER include headers inside namespaces, unless you do some preprocessor tricks. #include "vector.h" means: insert here the text stored in vector.h.
Advertisement
Also beware of running afoul of this.
I supose I could create all classes in one header file, all classes will have acces to all other classes and only one header is neaded.

// mymath.h#ifndef MYMATH_H#define MYMATH_H namespace MyMath{class Vector3;class Matrix4;class Quaternion;class Vector3{//Vector3 stuff};class Matrix4{//Matrix4 stuff};class Quaternion{//Quaternion stuff};}#endif


But if I for some reason realy need to have the different classes declared in separat headers and all classes need instances of each other. Obviously the more math classes hat performes operations using othe classes the more troublesome it gets.
Quote:Original post by HermanssoN
I supose I could create all classes in one header file, all classes will have acces to all other classes and only one header is neaded.

*** Source Snippet Removed ***

But if I for some reason realy need to have the different classes declared in separat headers and all classes need instances of each other. Obviously the more math classes hat performes operations using othe classes the more troublesome it gets.
Having the different classes access each other directly shouldn't be a problem, as long as you pass by reference and use forward declarations. I suspect the problem is that you still have your files organized incorrectly.

Also, remember that you can use non-member functions as well as member functions. A function that, say, converts a quaternion to a matrix is a good candidate for a non-member function. Furthermore, making it a non-member function can (potentially) eliminate the matrix class' dependency on the quaternion class.

Also, be sure to read this if you haven't already.

This topic is closed to new replies.

Advertisement