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 に答える