1 / 10

CMSC 341

This article covers topics such as object relations, inheritance, exceptions, and makefile management in C++. It explains concepts like "uses-a", "has-a", and "is-a" relationships, as well as the benefits and alternatives of using exceptions. Additionally, it provides an overview of makefiles, dependency graphs, targets, and macros.

Download Presentation

CMSC 341

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CMSC 341 C++ & Makefile Review

  2. Object Relations “Uses a” • An object uses another object by calling a public method of that object “Has a” • Implemented using composition (aggregation) • i.e. object Foo has an object Bar as a data member “Is a” • An object builds off of a base object to extend its functionality (inheritance) • Typically derived class is a specialized version of its base class

  3. Inheritance • Single Inheritance • Multiple Inheritance • The “Diamond Problem”

  4. Exceptions • The author of a library/class can detect run-time errors, but does not in general know what to do with them • The user of a library/class can cope with such errors, but can not detect them (otherwise they would have been handled in the users code and not left to the library to find)

  5. Exceptions • Notion of an exception is provided to deal with such problems • General idea is that when a function/method encounters a problem it can not cope with, it throws an exception, hoping that its caller (indirect or direct) can handle the problem

  6. Exception Alternatives • Terminate the program • Return a value representing an error • Return a legal value and leave the program/object in an illegal state • Call a function to be supplied in case of an error

  7. Exception Benefits • Removes error handling code from the code that caused the error (less clutter) • Makes it possible to catch all kinds of errors, errors of a certain type, or errors of related types • Usually used in situations in where the system can recover • Used when the error will be dealt with by a different part of the program (i.e., different scope) from that which detected the error

  8. Exception Examples • Throwing / Catching exceptions • General Form • Grouping of exceptions • Order of catching • Complex exceptions

  9. Makefiles • The make command allows you to manage large programs or groups of programs • As you begin to write larger programs, you will be begin to notice that you usually only work on a small section of the program, and the remainder of the program remains unchanged • The make program helps you in developing large programs by keeping track of which portions of the entire program have been changed and compiling only those parts which have changed since the last compile

  10. Makefiles • Dependency Graph • How it works • Targets / Dependencies • Main Target • Macros • Phony Targets

More Related