我正在使用 IMidiQueue将 IMidiMsg
对象排队/添加到我的 IMidiQueue mMIDICreated;
有时,我想检索我在上面添加的项目数。我试过这个:
char buffer[50];
sprintf(buffer, "size %d\n", sizeof(mMIDICreated) / sizeof(IMidiMsg));
OutputDebugString(buffer);
但是在添加了 8 个项目之后:
for (int i = 0; i < 4; i++) {
IMidiMsg* one = new IMidiMsg;
// ...
mMIDICreated.Add(one);
IMidiMsg* two = new IMidiMsg;
// ...
mMIDICreated.Add(two);
}
它返回 2,而不是 8。我哪里错了?
最佳答案
sizeof
将返回对象或类型本身的大小,它是一个常量,在编译时计算,与只有在运行时才能知道的项数无关。
你应该使用IMidiQueue::ToDo
:
Returns the number of MIDI messages in the queue.
关于c++ - 如何检索此数组的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36403098/