#3626. [GESP202309 六级 C++] 第 8 题
[GESP202309 六级 C++] 第 8 题
有关下面 C++ 代码的说法,错误的是( )。
#include <iostream>
using namespace std;
class MoreData {
int * __data;
int head, tail, capacity;
public:
MoreData(int cap) {
capacity = cap;
__data = new int[capacity];
head = tail = 0;
}
MoreData & push(int val) {
__data[tail++] = val;
return *this;
}
int pop() {
return __data[head++];
}
int size() {
return tail - head;
}
};
int main() {
auto myData = MoreData(100);
myData.push(1);
myData.push(2);
myData.push(3);
myData.push(11).push(12).push(13);
cout << myData.pop() << endl;
return 0;
}
{{ select(1) }}
MoreData类可用于构造队列(Queue)数据结构。- 代码第
29行,连续push()的用法将导致编译错误。 __data是MoreData类的私有成员,只能在类内访问。- 以上说法均没有错误。