Reputation: 6545
I have the following struct to manage Camera State with
struct keyState
{
float x_rotation, y_rotation, z_rotation;
float x_rotation_rad, y_rotation_rad, z_rotation_rad;
float x_pos, y_pos, z_pos;
} state_manager;
This struct is located in my WalkingCameraManipulator.h class. WalkingCameraManipulator is implemented in WalkingCameraManipulator.cpp, and I have an #include "WalkingCameraManipulator" in my main class.
Error 1 error LNK2005: "struct keyState state_manager" (?state_manager@@3UkeyState@@A) already defined in main.obj Error 2 error LNK1169: one or more multiply defined symbols found
However, I am dealing with the following error message and need to find the best place for my struct. Any ideas on what I can do here? Thanks in advance.
Upvotes: 1
Views: 1907
Reputation: 258568
The trailing state_manager
defines an instance. In a header. Which is wrong. I suggest you refactor your code as:
struct keyState
{
float x_rotation, y_rotation, z_rotation;
float x_rotation_rad, y_rotation_rad, z_rotation_rad;
float x_pos, y_pos, z_pos;
} ;
extern keyState state_manager;
//somecppfile.cpp
keyState state_manager;
The extern
part is a declaration, and the definition is now in a single implementation file. This mimics your intended behavior, but is probably not what you really want. Do you really want a global instance of keyState
? If not, remove it alltogether:
struct keyState
{
float x_rotation, y_rotation, z_rotation;
float x_rotation_rad, y_rotation_rad, z_rotation_rad;
float x_pos, y_pos, z_pos;
} ;
Upvotes: 5