0
votes

I am trying to implement a vitual Keyboard class for that I am having different keyboard layouts as shown.

KeyBoard.hpp

 class CKeyBoard 
 {
    public:

    enum eKeyBoardLayout
    {
        UPPER_CASE_ALPHABETS,
        LOWER_CASE_ALPHABETS,
        UPPER_CASE_NUMBERS,
        LOWER_CASE_NUMBERS,
        MAX_KEYBOARDLAYOUTS,
    };
    CKeyBoard();
    void hideCharacters(bool hide); // for password
    void setDisplayBufferLength(UNSIGNED8_T maxCharToDisplay);
    virtual ~CKeyBoard();
    static const UNSIGNED8_T const_noOfRows = 0x03; // 3 rows for character keys
    struct SLayout
    {
        UNSIGNED8_T noOfColumns[const_noOfRows];    ///< noofcolumns in each row may be different
        TypedText     textAreaFont; 
        const KeyMapping* pKeyMapping;
    };
    static const SLayout m_KeyBoardLayouts[MAX_KEYBOARDLAYOUTS];
private:
    /*methods*/
    void setKeyBoardLayout(eKeyBoardLayout);
    void backspacePressedHndlr();
    void letterCasePressedHndlr();
    void alphabetNumberToggleHndlr();
    /*members*/
    static const UNSIGNED8_T const_maxNoOfKeysSupprtd = 26;
    CKey m_keyArray[const_maxNoOfKeysSupprtd]; 
    CMenuItem m_KeySpaceBar;
    CMenuToggle m_KeyCaseSwitch;
    CMenuToggle m_KeyAlphaNum;
    CMenuItem m_keyBackSpace;
    eKeyBoardLayout m_eCurrentKeyLayout;
    CKeyBoardDisplayArea m_DisplayArea;

};

I am initialising the static member as follows in cpp file. KeyBoard.cpp

static const CKeyBoard::SLayout   m_KeyBoardLayouts[CKeyBoard::MAX_KEYBOARDLAYOUTS] = \
  {
      //      UPPER_CASE_ALPHABETS,
    {
      { 10, 9, 7 },
        TypedText(T_KEYBOARD),
        &keyMappingsAlphaUpper[0],

},
//      LOWER_CASE_ALPHABETS,
{
    { 10, 9, 7 },
    TypedText(T_KEYBOARD),
    &keyMappingsAlphaLower[0],
},
//      UPPER_CASE_NUMBERS,
{
    { 10, 10, 5 },
    TypedText(T_KEYBOARD),
    &keyMappingsNumLower[0],
},
//      LOWER_CASE_NUMBERS,
{
    { 10, 10, 5 },
    TypedText(T_KEYBOARD),
    &keyMappingsNumLower[0]
},


};
// Other function definitions
CKey::CKey() : m_pCallback(NULL)
{
}

But still I am getting unresolved external symbol as linker error. What am I doing wrong here?

Error Details: * error LNK2001: unresolved external symbol "public: static struct CKeyBoard::SLayout const * const CKeyBoard::m_KeyBoardLayouts" (?m_KeyBoardLayouts@CKeyBoard@@2QBUSLayout@1@B) *

1

1 Answers

2
votes

You forgot to add the class scope:

static const CKeyBoard::SLayout   
    CKeyBoard::m_KeyBoardLayouts[CKeyBoard::MAX_KEYBOARDLAYOUTS]

It's actually a pity the compiler doesn't warn about static linkage like that... It's a common mistake.