![](/img/trans.png)
[英]C++ Is writing and reading a variable from different threads undefined behavior
[英]c++ undefined variable while reading in data
我正在嘗試從數據文件中讀取值。 除了進入lol.GetNextItem(x);一切都可以編譯。 它說x是未聲明的標識符和未定義。 我不太確定如何解決它。 我相信我已經附上了解決此問題所需的代碼部分,但是如果需要其余部分,請告訴我。
class SortedList
{
private:
int length;
ItemType values[MAX_ITEMS];
int currentPos;
public:
void GetNextItem(ItemType &x);
}
void SortedList:: GetNextItem(ItemType &x)
{
currentPos++;
}
int main()
{
ifstream bug;
int i = 0;
int size = 0;
bug.open("num.dat");
float values[10];
while (!bug.eof())
{
bug >> values[i];
i++;
size++;
}
SortedList lol;
lol.GetNextItem(x);
bug.close();
return 0;
}
修改此代碼:
SortedList lol;
ItemType x; // insert this line
lol.GetNextItem(x);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.