Public Group

Something I should know, but don't

This topic is 4625 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

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.

Share on other sites

e.g.

Matrix4::Matrix4(const Quaternion& q){    ...}Quaternion Matrix4::toQuaternion() const{    return Quaternion(...);}

Share on other sites
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.

Share on other sites
You need forward class declarations.

class Matrix4; at the top of Quaternion.h

and

class Quaternion; at the top of Matrix4.h

Share on other sites
... d'oh! I did know the answer, I just couldn't find it inside my brain. Thanks for helping me find it.

• 17
• 11
• 11
• 9
• 49
• Forum Statistics

• Total Topics
631394
• Total Posts
2999753
×