C++PTA填空题

本文介绍了C++中的指针和引用,它们作为数据传递的工具,以及类和对象的概念,包括类的成员(数据成员和成员函数)、接口与实现的分离、访问控制(公有和私有成员)、结构体的区别、静态成员的特性、友元函数、继承关系和多态性。虚拟函数则允许在运行时确定调用的正确函数,增强了代码的灵活性。
摘要由CSDN通过智能技术生成

  1.

A pointer allows us to pass   potentially large amounts of data around at low cost: instead of copying the data we simply pass its  address  as a pointer value. The type  of the pointer determines what can be done to the data through the pointer.

2.

Like a pointer, a reference is an alias for an object, is usually implemented to hold a machine address   of an object, and does not impose performance overhead compared to pointers, but it differs from a pointer in that:

• You access a reference with exactly the same  syntax as the name of an object.

• A reference always refers to the object to which it was  initialized  .

• There is no "null reference," and we may assume that a reference refers  to an object.

3.

A reference is an alternative name  for an object, an alias. The main use of references is for specifying arguments and return values for functions in general and for overloaded operators in particular.

4.

A class is a user-defined  data-type .

A class consists of a set of members. The most common kinds of members are data members

 and member functions   .
A class is a namespace containing its members.

5.

C++ classes are a tool for creating new types that can be used as conveniently as the built-in types.
The fundamental idea in defining a new type is to separate the incidental details of the implementation  (e.g., the layout of the data used to store an object of the type) from the properties essential to the correct use of it (e.g., the complete list of functions that can access the data). Such a separation is best expressed by channeling all uses of the data structure and its internal housekeeping routines through a specific  interface  .

6.

The public members provide the class’s ​​​interface  and the private members provide implementation details. Members are accessed using . (dot) for ​​objects​​ and −> (arrow) for pointers.

7.
A struct is a class where members are by default ​​​public​​.

8.基本概念

类是对象的抽象,而一个对象则是其对应的一个 实例

9.基本概念

在面向对象程序设计方法中,对象是系统中用来描述客观事物的一个实体,它由 数据 和可执行的一组操作共同组成。

10.

除了可以通过对象名来引用静态成员,还可以使用引用 类名 静态成员。

11.

静态数据成员初始化必须在  类外  进行。

12.

A variable that is part of a class, yet is not part of an object of that class, is called a  static member. There is exactly one    copy of a static member instead of one copy per object, as for ordinary non-static members.

13.

By declaring a nonmember function a   friend​, the function can access the private part of the class declaration. That is, a function declared friend is granted ​access  to the implementation of a class just like a member function but is otherwise independent of that class.

14.

In a(n) ____is-a______ relationship, an object of a derived class also can be treated as an object of its base class.

15.

A base class's ____protected______ members can be accessed only in the base-class definition or in derived-class definitions.

16.

A binary operator can be defined by either a non-static member function taking one   argument or a nonmember function taking  two   arguments.

17.

 A unary operator, whether prefix or postfix, can be defined by either a non-static member function taking   no  arguments or a nonmember function taking  one   argument.

18.

The name of an operator function is the keyword  operator   followed by the  operator itself, for example, operator<<. An operator function is declared and can be called like any other function. A use of the operator is only a shorthand for an  explicit  call of the operator function.

虚函数:

19.

Virtual functions overcome the problems with the type-field solution by allowing the programmer to declare functions in a base class that can be   redefined  in each derived class. The compiler and linker will guarantee the  correct  correspondence between objects and the functions applied to them.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值