我正在尝试实现一个虚拟键盘类,因为我有不同的键盘布局,如图所示。
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;
};
我在cpp文件中初始化静态成员,如下所示。 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)
{
}
但是我仍然得到未解析的外部符号作为链接器错误。 我在这里做错了什么?
错误详细信息: * 错误LNK2001:未解析的外部符号&#34; public:static struct CKeyBoard :: SLayout const * const CKeyBoard :: m_KeyBoardLayouts&#34; (?m_KeyBoardLayouts @ @@ CKeyBoard @ 2QBUSLayout 1 @ B) *
答案 0 :(得分:2)
您忘了添加课程范围:
static const CKeyBoard::SLayout
CKeyBoard::m_KeyBoardLayouts[CKeyBoard::MAX_KEYBOARDLAYOUTS]
实际上很遗憾,编译器并没有像这样警告静态链接......这是一个常见的错误。