如何在头文件中的数组中声明连续的资源ID范围? 我将这些RID附加到菜单中。
答案 0 :(得分:0)
你需要的只是一个数组。你可以在不使用丑陋的定义的情况下获得几乎相同的语法:
<强> C ++ 11 强>
#include <algorithm> //for std::iota
#include <array> //for std::array
//Here's an array of 10 ints, consider changing the name now
std::array<int, 10> IDM_POPUP_LAST;
//This fills the array with incrementing values, starting at 100
std::iota (std::begin (IDM_POPUP_LAST), std::end (IDM_POPUP_LAST), 100);
//Now we can use them almost like before
appendToMenu (/*...*/, IDM_POPUP_LAST[3]); //uses value 103
//We can also loop through all of the elements and add them
for (const int i : IDM_POPUP_LAST) {
AddToLast (i);
}
<强> C ++ 03 强>
#include <algorithm> // for std::for_each
#include <vector> //for std::vector
std::vector<int> IDM_POPUP_LAST (10); //make array
for (std::vector<int>::size_type i = 0; i < IDM_POPUP_LAST.size(); ++i) //loop
IDM_POPUP_LAST [i] = i + 100; //assign each element 100, 101, etc.
appendToMenu (/*...*/, IDM_POPUP_LAST[3]); //use an element
std::for_each (IDM_POPUP_LAST.begin(); IDM_POPUP_LAST.end(); AddToLast); //add