classes in C++ Flashcards

1
Q

using classes in C++

A

• inside class, members referred to by name
• outside class, full name of member used
(i.e. class-name::Member name)

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

what are overloaded functions?

A

functions with different implementations based on the number and/or types of arguments

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

dynamic memory allocation in C++

A
  • new T create a new instance of type T and returns a pointer to it (new also calls any constructor)
  • delete x calls any destructor then deallocates memory
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

pointers

A
  • if x is an object, x.y refers to member y of x
  • if x is a pointer, x->y refers to member y of object pointer to by x
  • “this” is a pointer to the object for which the function was called (only legal in member function)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what is inheritance?

A

the reuse of code and variables in a derived class

C++ supports inheritance and multiple inheritance

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

C++ supports three access modifiers

A

1) public - anyone can access
2) private - only this class can access
3) protected - this class and its subclasses can access

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

what is polymorphism?

A
  • ability to use a subclass where a superclass is expected
  • functions of the subclass are invoked (rather than those of superclass)
  • C++ supports it (only functions marked as virtual are polymorphic)
  • a run-time thing
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what are templates?

A
  • another way to achieve reuse is through genericity
  • achieved through parameterized types
  • happens at compile time
  • each use of a template with a different type parameter creates a new type at run-time
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

pros and cons of templates

A
  • no runtime expense
  • catch more errors at compile time (good)
  • programs suffer from code bloat
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

two ways to give re-use

A

polymorphism: errors aren’t caught until run-time, slower code
templates: catch more errors at compile-time, suffers from code bloat

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