初始化结构的内容我有一个结构:无法访问地图
typedef struct
{
Qt::Key qKey;
QString strFormType;
} KeyPair;
现在我初始化密钥对实例,所以我可以用它为我自动测试应用程序。
KeyPair gDial[] =
{
{ Qt::Key_1 , "MyForm" },
{ Qt::Key_1 , "SubForm" },
{ Qt::Key_Escape, "DesktopForm" }
};
KeyPair gIP[] =
{
{ Qt::Key_1 , "MyForm" },
{ Qt::Key_2 , "Dialog" },
{ Qt::Key_2 , "Dialog" },
{ Qt::Key_Escape, "DesktopForm" }
};
....
and like 100 more instantiations....
当前,我调用一个使用这些KeyPair的函数。
我愿把所有这些密钥对实例的地图,这样我就不必调用pressKeyPairs()和qDebug()一百倍......我在使用MAPS一个新手.. ,所以我尝试:
map<string,KeyPair> mMasterList;
map<string,KeyPair>::iterator it;
mMasterList.insert(pair<string, KeyPair>("Testing Test Menu", *gDial)); //which I know is wrong, but how?
mMasterList.insert(pair<string, KeyPair>("Testing IP Menu", *gIP));
mMasterList.insert(pair<string, KeyPair>("IP Menu2", *gIP2));
....
for (it=mMasterList.begin() ; it != mMasterList.end(); it++)
{
qDebug() << (*it).first << endl;
pressKeyPairs((*it).second);
// I don't know how to access .second ... this causes a compiler error
}
编辑: pressKeyPairs被声明为:
template <size_t nNumOfElements> void pressKeyPairs(KeyPair (&keys)[nNumOfElements]);
此代码块不工作... :(有人可以告诉我如何正确地把这些密钥对中一个Map?
这就是`pressKeyPairs`的定义,你的编译错误是什么? – 2011-02-11 07:51:11
你得到的编译器错误是什么?另外,我的猜测是pressKeyPairs()得到一个const KeyPair&但你使用的是一个迭代器而不是一个const_iterator(因为它应该可以做,因为它更“正确”) – gnobal 2011-02-11 07:51:57
编译器错误:没有匹配函数`pressKeyPairs(KeyPair&)' – Owen 2011-02-11 08:02:38