选择题--01

来源:互联网 发布:java导出pdf 编辑:程序博客网 时间:2024/04/29 11:21

1.c++不能重载的运算符有.(点号),::(域解析符),?:(条件语句运算符),sizeof(求字节运算符),typeid,static_cast,dynamic_cast,interpret_cast(三类类型转换符)。

2.有一个类B继承自类A,他们数据成员如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class A {
...
private:
   int &a;
};
class B : public A {
...
private:
     int a;
public:
     const int b;
     A c;
     static const char* d;
     A* e;
};
则构造函数中,成员变量一定要通过初始化列表来初始化的是____。
b c
b c e
b c d e
c e
b d
b e


在构造函数中需要初始化列表初始化的有如下三种情况 1.带有const修饰的类成员 ,如const int a ;
2.引用成员数据,如 int& p;
3.带有引用的类变量,如: class A {
private:
       int &a;
};
class B{
private:
  A c;
}
这里的c需要用初始化列表进行初始化。

3test.c文件中包括如下语句:
1
2
3
4
#define INT_PTR int*
typedef int* int_ptr;
INT_PTR a,b;
int_ptr c,d;
文件中定义的四个变量中,哪个变量类型不是指针类型?
a
b
c
d
都是指针
都不是指针


#define INT_PTR int* 这是宏定义,编译预处理阶段要进行宏替换,INT_PTR a,b会变成 int* a,b 所以b不是指针类型
typedef int* int_ptr; 这是自定义类型,也就是把int_ptr定义为 int型指针,编译阶段会把c,d都识别为指针

0 0
原创粉丝点击