如何检查具有确定值的指针数组的索引
how to check an index of array of pointers which has a certian value?
我是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
将有助于
相关文章:
- 当该数组的索引中没有元素时,指针指向什么?
- 通过指针与数组引用扩展数组索引序列
- C++ STL 数据结构常时按索引推送/弹出/随机访问,并具有指向元素的可靠指针
- 矢量指针索引处的读取元素
- 通过在编译时折叠带有索引的指针来分配 C 数组
- C++娜娜 如何从全局列表框*指针访问列表框内的索引 0 上的按钮?
- 是否可以创建带有索引但没有指针的单个链表?
- 创建一个没有指针但有索引的链表
- 运行时错误:基0x000000000000溢出到0xffffffffffffffff的指针索引表达式 (basic_st
- 如何查找指向数组中元素的指针的索引
- 如何使用 C+ 中的指针访问数组中的特定索引
- 从指针数组中的地址索引
- 混合索引和指针算术时避免使用C4365,而无需铸造
- 如何在指针初始化为数组的第一个索引后释放指针
- 基于索引的 alloca 返回的指针访问和"placement new"的效果
- 是否可以使用一系列智能指针来自动通过其索引更新其值
- 指针数组总是从索引C 生成一个
- 将指针分配给字符串对象的第一个也是最后一个索引
- 为对象指针数组的每个空索引创建新对象
- 试图通过指针索引对象数组的数组时出现分段错误