3. Developing C++ Classes Flashcards

1
Q

True or false?

If we do not provide any custom constructors, the compiler provides an automatic default constructor to our class for free!

A

True.

The automatic default constructor will only initialize all member variables to their default values.

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

True or false?

A class can only have one constructor.

A

False.

In addition to the default constructor, you can also specify custom constructors that accept arguments.

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

True or false?

Providing any constructor at all prevents the automatic default constructor provided by C++ from being created.

A

True.

Even if your custom constructor accepts three arguments, the default constructor that accepts zero arguments will not be created automatically.

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

What is a copy constructor?

A

A copy constructor is a special constructor that allows us to make a copy of an existing object.

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

True or false?

If we don’t provide a custom copy constructor, the compiler will provide an automatic copy constructor for us.

A

True.

The automatic copy constructor will copy the contents of all member variables.

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

When are copy constructors invoked automatically?

A
  • Passing an object as a parameter (by value)
  • Returning an object from a function (by value)
  • Initializing a new object
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a copy assignment operator?

A

A copy assignment operator defines the behavior when an object is copied using the assignment operator.

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

What’s the difference between a copy constructor and an assignment operator?

A

A copy constructor creates a new object.

An assignment operator assigns a value to an existing object (it’s called on an object that has already been constructed.

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

Name 3 different ways to pass variables around to functions.

A
  • Pass by value (default)
  • Pass by pointer
  • Pass by reference
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Name 3 different ways to return variables from functions.

A
  • Return by value (default)
  • Return by pointer
  • Return by reference
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

True or false?

If we don’t provide any custom destructor, the compiler provides an automatic default destructor to our class for free!

A

True.

The only action of the automatic default destructor is to call the default destructor of all member objects.

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