c++ - 如何访问堆栈中对象的成员?C++
问题描述
如何分配/读取堆栈中对象的成员?
struct item{
char opra;
int count;
double operand;
};
stack<item> S;
double test = S.top.operand;
它不起作用,谢谢。
解决方案
Top 是一个方法,所以你应该调用S.top().operand
. 我让它像这样编译:
#include <iostream>
#include <stack>
struct item{
char opra;
int count;
double operand;
};
int main(){
std::stack<item> S;
double test = S.top().operand;
return 0;
}
推荐阅读
- swift - MapKit 中的中心位置在 UiLabel 中不可见
- javascript - 如何从内部 HTML 文件运行 React 代码?
- php - 选择的复选框值到不同的页面
- java - 当使用一个对象作为字段(关联)与方法参数(依赖)作为另一个对象内部时
- swift - 如何在 swift 3.0 中使用 performSegue?
- javascript - 如何在javascript中将数组值一一分配给setTimeout
- python - python imblearn make_pipeline TypeError:Pipeline的最后一步应该实现fit
- node.js - puppeteer 无法处理对话
- android - 下载大文件时出现 java.lang.NullPointerException
- php - 警告:file_get_contents():无法设置本地证书链文件