初始化一个由 p 指向的新 INTSTK,它最多可以存储 m 个
//initialize a new INTSTK pointed by p which can store at most m ntegers
struct INTSTK{
int *const e; //points to memory allocated to store integers
const int m; //maximum number of integers the stack can holds
int t; //top indicator or number of integers in the stack;
void initSTK (INTSTK *const p, int m);
};
我需要有关初始化STK函数定义的帮助 void initSTK(INTSTK *const p, int m( { 初始化一个由 p 指向的新 INTSTK,该 INTSTK 最多可以存储 m 个 ntegers
}
除了构造之外,您不能在其他任何地方修改const
成员变量。
试试这个:
struct INTSTK{
int *const e; //points to memory allocated to store integers
const int m; //maximum number of integers the stack can holds
int t; //top indicator or number of integers in the stack;
INTSTK(int m_) : e(new int[m_]), m(m_), t(0) {}
};
void initSTK (INTSTK *const p, int m) {
// assuming input is already populated with type `INTSTK *const`
new (p) INTSTK(m);
}
相关文章:
- 将字符串存储在c++中的稳定内存中
- std::原子加载和存储都需要吗
- C++:将控制台输出存储在宏中更好吗
- 使用QProcess执行命令,并将结果存储在QStringList中
- 访问存储在向量C++中的结构的多态成员
- 如何从存储在std::映射中的std::集中删除元素
- 存储模板类型以强制转换回派生<T>
- 类型总是使用其大小存储在内存中吗
- 当字符串存储在变量中时,如何将字符串转换为wchar_t
- 使用无符号字符数组有效存储内存
- 如何在cpp.中使用协议缓冲区存储大缓冲区/数组(char/int)
- 使用 pqxx 将 std::vector 存储在 postgresql 中,并从数据库中检索它
- 带结构的二维矢量:如何存储元素
- 添加存储在向量中的大整数的函数出现问题
- 从文件中读取多个字节,并将它们存储在C++中进行比较
- 在std::vector上存储带有模板的类实例
- 谷歌测试中的期望值存储在哪里
- 为什么C中的通用链表中存储的数据已损坏
- 在c++中获取两个大int,并将它们存储在数组中
- 初始化一个由 p 指向的新 INTSTK,它最多可以存储 m 个