如何检查具有确定值的指针数组的索引

how to check an index of array of pointers which has a certian value?

本文关键字:指针 索引 数组 何检查 检查      更新时间:2023-10-16

我是c++的新手,我正在努力掌握指针和数组的概念,所以我的问题是我有一个名为"reservation"的类,它为未发酵的保留保留保留了一个等待列表我有一个指针数组。我的问题是如何使用指针数组检查保留是否为1?

比方说

reservation** wait[i] ; // my array of pointers
if (wait[i]==1) // does this mean that i am checking if the index value is one? 

非常感谢你的回答,如果你愿意的话,我想对这个话题做进一步的解释

第一个:reservation** wait[i] ; // my array of pointers
你最好用大写字母作为类名
您声明的是指向类reservation
对象的指针的指针数组如果i是数组的长度,则不能使用变量作为数组的长度。它需要在编译时给定为常量

所以你应该写的是:

const int SIZE = 50; // change the value as you like
Reservation* wait[SIZE] ; // my array of pointers

现在要检查索引i处的预订是否可用,应该有一个您可以访问的成员给您,类似于:

    if (wait[i] -> isReserved()) // you can access field from a pointer using ->
                                  // assuming isReserved() is a member of reservation
                                 // that returns a boolean

显示您的类reservation将有助于