错误:未在此范围内声明 slist

ERROR: slist was not declared in this scope

本文关键字:范围内 声明 slist 错误      更新时间:2023-10-16

这段代码对我不起作用,我遇到了下面提到的编译错误。有人请帮助我指出我的错误。

In function 'int main()':
4:3: error: 'slist' was not declared in this scope
4:9: error: expected primary-expression before 'int'
5:3: error: 'L' was not declared in this scope
12:9: error: expected primary-expression before 'int'
13:3: error: 'back' was not declared in this scope

法典:

int main() {
  slist<int> L;
  L.push_front(0);
  L.push_front(1);
  L.insert_after(L.begin(), 2);
  copy(L.begin(), L.end(),        // The output is 1 2 0
       ostream_iterator<int>(cout, " "));
  cout << endl;
  slist<int>::iterator back = L.previous(L.end());
  back = L.insert_after(back, 3); 
  back = L.insert_after(back, 4);
  back = L.insert_after(back, 5);
  copy(L.begin(), L.end(),        // The output is 1 2 0 3 4 5
       ostream_iterator<int>(cout, " "));
  cout << endl;
}

所有的问题都归结为以下声明

slist<int> L;

抛出的错误

slist未在此范围内声明

您需要确保在范围内声明slistinclude必要的标头。