W2 P3: Classes and Scoped Enumerations Flashcards

1
Q

Three class types:

A
class
struct
union
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

True or False: a Subject class may include a data member of Subject* type

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

True or False: a Subject class may include a data member of Subject type

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to combine a class definition with the definition of one or more class instances:

A

class-key Identifier {

 sub-object declarations

 member function declarations

} identifier;

ex.
 class Subject {
     unsigned number;
     char desc[41];
 } subject, *pSubject;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to initialize a data member directly from the constructor definition:

A

Class-name(type x, …) : data-member-name{x},… { // any logic }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is an anonymous class

A

A class without a class name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

2 ways of defining an anonymous class:

A
// defining an instance of an
 // anonymous type (name)
 class Subject {
     int number;
     struct { // definition - no tag
         char shortName[7];
         char fullName[41];
     } identifier;
 }

or

// declaring a synonym type (Course)

typedef struct { // synonym - no tag
unsigned number;
char desc[41];
} Course;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Prototypes for move constructors and move-assignment operators:

A

The prototype for a move-constructor takes the form

Class-name(Class-name&&);

The prototype for a move-assignment operator takes the form

Class-name& operator=(Class-name&&);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Call move assignment operator:

A

class1 = std::move(class2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a class variable?

A

A class can include data members that hold the same information for all instances of the class and access that information regardless of the number of instances that currently exist. These are called class variables.

The keyword static declares a variable in a class definition to be a class variable.

ex.

unsigned Horse::noHorses = 0; // initializer

 class Horse {
     unsigned age;
     unsigned no;
 public:
     static unsigned noHorses;
     Horse(unsigned a);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a class function?

A

A class function provides access to private class variables. The keyword static declares a function in a class definition to be a class function.

ex.
 class Horse {
     unsigned age;
     unsigned no;
     static unsigned noHorses;
 public:
     Horse(unsigned a);
     void display() const;
     ~Horse();
     static unsigned howMany();
 };

unsigned Horse::howMany() { return noHorses; }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a union?

A
  • Members are public by default
  • members of a union share the same address
  • can only hold the value of one member at a time
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is an enumeration?

A

A type that holds a discrete set of symbolic constants.

  • simplifies the readability and the upgradeability

ex.
enum Colour {white, red, green, blue};

std::ostream& operator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly