Something I should know, but don't

Started by
3 comments, last by _goat 18 years, 6 months ago
I have a Quaternion structure, and a Matrix4 structure. They are in different header files, and I would like to have constructors for both that take the other; for example: Quaternion::Quaternion(const Matrix4& matrix), and Matrix4::Matrix4(const Quaternion& q). Obviously, in Matrix4.h, I need to include Quaternion.h, and vice versa. Both files have inclusion guards, of course. However, I'm getting errors because, well, the names aren't resolving. The final real piece of information is that because I have several header files (Vector2, Vector3, ...), I have a header file (atma_math.h), which includes all of them, so only atma_math has to be included when someone wants to do any 3d mathematics. How is the linking (MSVC2005Express) happening, and how do I get it to work? I don't particularly want anyone to suggest different class architecture, because the solution to this problem will let me fix problems like this in the future, unless of course redoing the class architecture is the only way. Cheers.
[ search: google ][ programming: msdn | boost | opengl ][ languages: nihongo ]
Advertisement
Instead of adding a constructor to each class, try adding a constructor to one of them, and an additional toX() method.

e.g.

Matrix4::Matrix4(const Quaternion& q){    ...}Quaternion Matrix4::toQuaternion() const{    return Quaternion(...);}
Quote:I don't particularly want anyone to suggest different class architecture, because the solution to this problem will let me fix problems like this in the future, unless of course redoing the class architecture is the only way.


Edit: Oh yeah, and your method wouldn't work anyway, because the types are still being used inside the header class, which is the problem.
[ search: google ][ programming: msdn | boost | opengl ][ languages: nihongo ]
You need forward class declarations.

class Matrix4; at the top of Quaternion.h

and

class Quaternion; at the top of Matrix4.h
... d'oh! I did know the answer, I just couldn't find it inside my brain. Thanks for helping me find it.
[ search: google ][ programming: msdn | boost | opengl ][ languages: nihongo ]

This topic is closed to new replies.

Advertisement