I am trying to assign a static pointer in a class so I can access it by class functions.
Basically, the typeDef is defined in a third party header file.
typedef struct
{
CAN_TypeDef *Instance; /*!< Register base address */
CAN_InitTypeDef Init; /*!< CAN required parameters */
CanTxMsgTypeDef* pTxMsg; /*!< Pointer to transmit structure */
CanRxMsgTypeDef* pRxMsg; /*!< Pointer to reception structure */
__IO HAL_CAN_StateTypeDef State; /*!< CAN communication state */
HAL_LockTypeDef Lock; /*!< CAN locking object */
__IO uint32_t ErrorCode; /*!< CAN Error code */
}CAN_HandleTypeDef;
Here is my Test class header file "Test.hpp"
#pragma once
#include <stm32f4xx_hal.h>
class Test
{
public:
static CAN_HandleTypeDef* hcan1;
};
Here is the Test class code "Test.cpp"
#include "Test.h"
void DoSomething()
{
HAL_CAN_Receive(Test::hcan1, CAN_FIFO0, 100);
}
Here is the main function where I try to assign it a value
int main(void)
{
CAN_HandleTypeDef hcan1;
<-- Code is here that uses and populates hcan1 -->
// Initialize libraries
Test::hcan1 = &hcan1;
}
When I try to compile I get the "error : undefined reference to `Test::hcan1'"
I am new to cpp, but I know when you declare you have to also define. However, when I try to define it tells me I have multiple declarations.
What's the solution here?