• Advertisement
Sign in to follow this  

Something I should know, but don't

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
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(...);
}

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement