Sign In | Subscribe
Start learning today, and be successful in your academic & professional career. Start Today!
Loading video...
This is a quick preview of the lesson. For full access, please Log In or Sign up.
For more information, please see full course syllabus of Intermediate C++
  • Discussion

  • Study Guides

  • Download Lecture Slides

  • Table of Contents

  • Related Services

Bookmark and Share
Lecture Comments (1)

0 answers

Post by Ram Manohar Oruganti on November 13, 2014

Mr. Sylvain, so I am selectively picking the videos I have to watch to understand object oriented programming first. I would be glad if you could tell me as to which lecture talks about static functions, static variables, const functions, inline functions etc.

Namespaces

  • Copy a new version of your “Auto” homework. Remove every line that reads: using namespace std;
    • That will mean adding “std::” to every element in the standard namespace.
  • Create a new namespace for each object class you defined. Call it: homework_cplusplus_educator_com
  • In any block or CPP file where you may have numerous uses of “cout”, “endl”, etc., add: using std::cout;
    • or, “std::endl”, or which ever name you’d like to use without the “std::” qualifier.
  • If you put the “main” function inside the same namespace as the other classes, remove it from that namespace. (It should be in a separate file anyway.) Now you’ll need to reference your classes with their namespace, e.g., “homework_cplusplus_educator_com::Auto”.
  • Add a namespace alias, such as “homework”, so you won’t need to type the entire namespace name for “homework_cplusplus_educator_com.” (This is not just to save on your typing; the code will also be easier to read.)
  • Make sure everything still compiles and runs!

Namespaces

Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.

  • Intro 0:00
  • Overview 0:15
  • Namespaces 5:27
    • Uses the 'Scope Operator'
    • Two Kinds: Standard Library and Classname
    • Helps Avoid Third Party Name Collision
  • 'Namespace' for Class Association 7:46
    • Scope
    • Example
    • Implementation in Separate File, Same Scope
  • Define a Namespace 10:05
    • Use 'namespace' Keyword, Valid Identifier, and Block to Add to a Namespace
    • Example
  • Units Can Share Namespace 12:26
    • 'std' Namespace
    • Include Namespace Declaration Block in Each Compilation Unit
  • Use Namespaces for Types, Classes 14:04
    • Compilation Unit: alpha.cpp
    • Compilation Unit: beta.cpp
    • Calling Unit
  • Don't Use Namespaces for Instances 15:21
    • Namespace Cannot Be Used to Duplicate Names of Object Instances in Different Compilation Units
    • Example
    • Error When Compilation Units Are Linked Together
  • Using Explicit Namespace 16:51
    • Header File for Class
    • Use of Namespace in Compilation Unit
  • 'Using' Keyword 17:36
    • Specify a Default Namespace
    • More Than One 'Using' Can Be Specified
  • Avoiding 'Using' 20:48
    • Third-Party Packages Often Avoid 'Using'
    • Example
  • Using for Particular Names 22:54
    • The 'Using' Keyword Can Set Up Just Certain Names for a Default Use
  • Naming Strategy 24:30
    • Unique Name, World-Wide
    • Avoid Confusion with Another Similar Name
    • Typical Advice: Use Company Website Name
  • Namespace Aliases 28:35
    • User Uses Certain Namespace with a Different Name
    • Example
  • Avoiding Duplicates 29:33