gpt4 book ai didi

c++ - 遍历 Vector 中结构的成员时出错

转载 作者:行者123 更新时间:2023-11-28 02:32:50 24 4
gpt4 key购买 nike

我的 .h 文件中有一个结构体和两个 vector :

struct FTerm {
int m_delay;
double m_weight;
};

std::vector<FTerm> m_xterms;
std::vector<FTerm> m_yterms;

我已经读入了一个文件来填充 m_xterms 和 m_yterms 的值,我正在尝试遍历这些值:

vector<FTerm>::iterator terms;

for (terms = m_xterms.begin(); terms < m_xterms.end(); terms++)
{
int delaylength = m_xterms->m_delay * 2; // Assume stereo
double weight = m_xterms->m_weight;
}

虽然我很确定我的逻辑有误,但我目前收到错误 Error expression must have a pointer type。卡在这一段时间了,谢谢。

最佳答案

改变

int delaylength = m_xterms->m_delay * 2;
double weight = m_xterms->m_weight;

int delaylength = terms->m_delay * 2;
// ^^^^^
double weight = terms->m_weight;
// ^^^^^

因为你想通过

访问值
vector<FTerm>::iterator terms;

在循环中

for (terms = m_xterms.begin(); terms < m_xterms.end(); terms++)
// ^^^^^

"Although I'm pretty sure I have the logic wrong, ..."

除非您提供有关逻辑要求的更多上下文,否则无法回答。

关于c++ - 遍历 Vector 中结构的成员时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28490284/

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