0

如何在头文件的数组中声明连续范围的资源 ID?我将这些 RID 附加到菜单中。

4

1 回答 1

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
于 2012-07-22T03:26:02.210 回答