gpt4 book ai didi

c++ - 如何检索此数组的大小?

转载 作者:行者123 更新时间:2023-11-30 00:47:00 25 4
gpt4 key购买 nike

我正在使用 IMidiQueueIMidiMsg 对象排队/添加到我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com