我想在OSX Yosemite下创建一个关键字识别子例程,参见下面的清单。我确实有一些奇怪的事情。结构向量的C++初始化
我正在使用“操场”来制作MWE,并且项目的构建看起来不错,但不想运行: “我的Mac运行OS X 10.10.5,它低于String sort的最低部署目标。 “ 我甚至不明白这条消息,特别是我的代码在排序时没有做什么。
然后,我将相关代码粘贴到我的应用程序中,在该应用程序中使用CMake生成项目,同一配置中的相同编译器和相同IDE以消息 显示“非聚合类型”矢量用“vector QInstructions = {..}”结构中的初始化程序列表“ ”进行初始化。
当搜索类似的错误消息时,我发现了几个类似的问题,并且建议的解决方案使用默认构造函数,手动初始化等。我想知道标准抗压缩初始化是否可行?
#include <iostream>
using namespace std;
#include <vector>
enum KeyCode {QNONE=-1,
QKey1=100, QKey2
};
struct QKeys
{ /** The code command code*/
std::string Instr; ///< The command string
unsigned int Length; ///< The significant length
KeyCode Code; //
};
vector<QKeys> QInstructions={
{"QKey1",6,QKey1},
{"QKey2",5,QKey2}
};
KeyCode FindCode(string Key)
{
unsigned index = (unsigned int)-1;
for(unsigned int i=0; i<QInstructions.size(); i++)
if(strncmp(Key.c_str(),QInstructions[i].Instr.c_str(),QInstructions[i].Length)==0)
{
index = i;
cout << QInstructions[i].Instr << " " <<QInstructions[i].Length << " " << QInstructions[i].Code << endl;
return QInstructions[i].Code;
break;
}
return QNONE;
}
int main(int argc, const char * argv[]) {
string Key = "QKey2";
cout << FindCode(Key);
}
请确保您的建筑物为C++ 11而非C++ 98. –
游乐场?据我所知,游乐场是一个迅速的功能。 – molbdnilo