# Something I should know, but don't

## 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
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 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.

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

• ### Forum Statistics

• Total Topics
628354
• Total Posts
2982236

• 10
• 9
• 11
• 24
• 11