gpt4 book ai didi

c++ - 如何访问堆栈中对象的成员? C++

转载 作者:行者123 更新时间:2023-12-02 10:04:21 26 4
gpt4 key购买 nike

如何在堆栈中分配/读取对象的成员?

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;
}

关于c++ - 如何访问堆栈中对象的成员? C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60991819/

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