相关试题
单选题 有关下面C++代码的说法,错误的是( )。 1 #include <iostream> 2 using namespace std; 3 4 class MoreData { 5 int * _data; 6 int head, tail, capacity; 7 public: 8 MoreData(int cap) { 9 capacity = cap; 10 _data = new int[capacity]; 11 head = tail = 0; 12 } 13 MoreData & push(int val) { 14 _data[tail++] = val; 15 return *this; 16 } 17 int pop(){ 18 return _data[head++]; 19 } 20 int size() { 21 return tail - head; 22 } 23 }; 24 int main() { 25 auto myData = MoreData(100); 26 myData.push(1); 27 myData.push(2); 28 myData.push(3); 29 myData.push(11).push(12).push(13); 30 cout << myData.pop() << endl; 31 return 0 ; 32 }
单选题 在C++中,类的静态成员变量只能被该类对象的成员函数访问。
单选题 在C++中,break语句只能用于循环语句和switch语句中。()
单选题 关于C++类和对象的说法,错误的是()。
单选题 数组在内存中是连续存储的,所以其随机访问效率很高。()
单选题 若有一个哈夫曼树,其叶子节点个数为n,则该哈夫曼树的节点总数为()
单选题 运⾏以下C++代码,屏幕将输出“derived class”。 #include <iostream> using namespace std; class base { public: virtual void show() { cout << "base class" << endl; } }; class derived : public base { public: void show() override { cout << "derived class" << endl; } }; int main() { base* b; derived d; b = &d; b->show(); return 0; }
单选题 有关下面C++代码的说法,错误的是( ) 1 #include <iostream> 2 using namespace std; 3 4 class MoreData { 5 int * _data; 6 int head, tail, capacity; 7 public: 8 MoreData(int cap) { 9 capacity = cap; 10 _data = new int[capacity]; 11 head = tail = 0; 12 } 13 MoreData & push(int val) { 14 _data[tail++] = val; 15 return *this; 16 } 17 int pop(){ 18 return _data[head++]; 19 } 20 int size() { 21 return tail - head; 22 } 23 }; 24 int main() { 25 auto myData = MoreData(100); 26 myData.push(1); 27 myData.push(2); 28 myData.push(3); 29 myData.push(11).push(12).push(13); 30 cout << myData.pop() << endl; 31 return 0 ; 32 }