Getting Started with C++

Michael Redlich
Michael RedlichSystems Analyst, Polymer Physicist at Amateur Computer Group of New Jersey
1
Getting Started with
C++
Trenton Computer Festival
March 17, 2018
Michael P. Redlich
@mpredli
about.me/mpredli/
Who’s Mike?
• BS in CS from
• “Petrochemical Research Organization”
• Java Queue News Editor, InfoQ
• Ai-Logix, Inc. (now AudioCodes)
• Amateur Computer Group of New Jersey
2
Objectives (1)
• What is C++?
• Evolution of C++
• Features of C++
• Review of Object-Oriented Programming
(OOP)
3
Objectives (2)
• Getting Started with C++
• introduction to the C++ class mechanism
• how to implement C++ classes
• Live Demos (yea!)
• C++ Resources
4
What is C++?
• “...a general purpose programming language
with a bias towards systems programming that
• is a better C,
• supports data abstraction,
• supports object-oriented programming,
• supports generic programming.”
Bjarne Stroustrup Web Site, http://www.stroustrup.com/C++.html
5
Evolution of C++ (1)
• Created by Bjarne Stroustrup
• AT&T Labs
• 1980 - originally named “C with
Classes”
• 1983 - redesigned and renamed to C++
• 1985 - available to the public
6
Evolution of C++ (2)
• 1989 - further extensions added
• templates and exception handling
• 1998 - C++ standardized
7
Features of C++
• Object-Oriented
Programming (OOP)
Language
• Pass-by-Reference
• Operator Overloading
• Generic Programming
• Exception Handling
• Namespaces
• Default Arguments
8
OOP Review (1)
• Programming Paradigm
• Four (4) Main Attributes
• data encapsulation
• data abstraction
• inheritance
• polymorphism
9
OOP Review (2)
• Abstract Data Type (ADT)
• user-defined data type
• use of objects through functions (methods)
without knowing the internal representation
10
OOP Review (3)
• Interface
• functions (methods) provided in the ADT that
allow access to data
• Implementation
• underlying data structure(s) and business logic
within the ADT
11
OOP Review (4)
• Class
• Defines a model
• Declares attributes
• Declares behavior
• Is an ADT
• Object
• Is an instance of a class
• Has state
• Has behavior
• May have many unique
objects of the same class
12
Advantages of OOP
• Interface can (and should) remain
unchanged when improving implementation
• Encourages modularity in application
development
• Better maintainability of code
• Code reuse
• Emphasis on what, not how
13
Some C++ Keywords
• class
• new, delete
• private,
protected, public
• try, throw, catch
• friend
• explicit
• virtual
• bool
• inline
14
Classes (1)
• A user-defined abstract data type
• Extension of C structs
• Contain:
• constructor
• destructor
• data members and member functions (methods)
15
Classes (2)
• Static/Dynamic object instantiation
• Multiple Constructors:
• Sports(void);
• Sports(char *,int,int);
• Sports(float,char *,int);
16
Classes (3)
• Class scope:
• scope resolution operator(::)
• Abstract Classes
• contain at least one pure virtual member
function (C++)
• contain at least one abstract method (Java)
17
Abstract Classes
• Pure virtual member function (C++)
• virtual void draw() = 0;
• Abstract method (Java)
• public abstract void draw();
18
Class Inheritance
19
20
// Sports class (partial listing)
class Sports {
private:
char *team;
int win;
public:
Sports(void);
Sports(char const *,int,int);
~Sports(void); // destructor
int getWin() const;
};
Sports::Sports(void) {
// define default constructor here...
}
Sports::Sports(const char *team,int win,int loss) {
// define primary constructor here...
}
int Sports::getWin() const {
return win;
}
21
// Baseball class (partial listing)
class Baseball : public Sports {
public:
Baseball(void);
Baseball(char const *,int,int);
~Baseball(void);
};
Baseball::Baseball(void) : Sports() {
}
Baseball::Baseball(const char *team,int win,int loss) :
Sports(team,win,loss) {
}
inline Baseball::~Baseball(void) {
}
Static Instantiation
• Object creation:
• Baseball mets(“Mets”,97,65);
• Access to public member functions:
• mets.getWin(); // returns 97
22
Dynamic Instantiation
• Object creation:
• Baseball *mets = new
Baseball(“Mets”,97,65);
• Access to public member functions:
• mets->getWin(); // returns 97
23
Deleting Objects
Baseball mets(“Mets”,97,65);
// object deleted when out of scope
Baseball *mets = new
Baseball(“Mets”,97,65);
delete mets; // required call
24
Operator new (1)
• Allocates memory on the free store (heap)
• Memory size is calculated by the compiler
• No more casting
• Automatic call to the constructor
• Used for built-in and user-defined data
types
25
Operator new (2)
int *var = new int; // int();
Sports *sports = new Sports();
// initializes an array of pointers
to type int
int *var = new int[10]
26
Operator delete (1)
• Deallocates memory on the free store
(heap)
• Automatic call to the destructor
• Must be used according to how operator
new was used
27
Operator delete (2)
int *var = new int;
delete var;
int *var = new int[10]
delete[] var;
28
Inline Member
Functions (1)
• Used for short functions (≤ 5 statements)
• Purpose:
• speed
• Good candidates for inline member
functions are those that access data
members
29
Inline Member
Functions (2)
• Explicit Use:
• use keyword inline in the definition of
member function
• Implicit Use:
• define the member function within its
declaration without using the keyword inline
30
Live Demo!
31
Popular C++
Compilers
32
• Embarcadero C++ Builder XE7
• embarcadero.com/products/cbuilder
• MicrosoftVisual C++
• microsoft.com
• Intel System Studio
• software.intel.com/en-us/c-
compilers
Popular C++
Compilers
33
• Open Watcom 1.9 (June 2010)
• openwatcom.org
Local C++ User
Groups
• ACGNJ C++ Users Group
• facilitated by Bruce Arnold
• acgnj.barnold.us
34
Further Reading (1)
35
• C & C++ Code Capsules
• Chuck Allison
• freshsources.com
• The C++ Programming Language
• Bjarne Stroustrup
• stroustrup.com/4th.html
Further Reading (2)
36
• The Annotated C++ Reference Manual
• Margaret Ellis and Bjarne Stroustrup
• stroustrup.com/arm.html
• 1997 C++ Public Review Document
• C++ ISO JTC1/SC22/WG21 Committee
• open-std.org/jtc1/sc22/open/n2356
Upcoming Events
• ACGNJ Java Users Group
• Dr. Venkat Subramaniam
• Monday, March 19, 2018
• DorothyYoung Center for the Arts, Room 106
• Drew University
• 7:30-9:00pm
• “Twelve Ways to Make Code Suck Less”
37
38
Thanks!
mike@redlich.net
@mpredli
redlich.net
slideshare.net/mpredli01
github.com/mpredli01
Upcoming Events
• March 17-18, 2017
•tcf-nj.org
• April 18-19, 2017
•phillyemergingtech.com
39
1 of 39

Recommended

Getting started with C++ by
Getting started with C++Getting started with C++
Getting started with C++Michael Redlich
78 views39 slides
Getting Started with C++ (TCF 2014) by
Getting Started with C++ (TCF 2014)Getting Started with C++ (TCF 2014)
Getting Started with C++ (TCF 2014)Michael Redlich
1.3K views38 slides
Introduction to java by
Introduction to javaIntroduction to java
Introduction to javaAbhishekMondal42
78 views15 slides
Fic (sendup dec17) cs lb by
Fic (sendup dec17) cs lbFic (sendup dec17) cs lb
Fic (sendup dec17) cs lbFazaia inter college lahore
94 views6 slides
Console applications IN C# by
Console applications IN C#Console applications IN C#
Console applications IN C#Sireesh K
414 views21 slides
Debugging Your Production JVM by
Debugging Your Production JVMDebugging Your Production JVM
Debugging Your Production JVMkensipe
7.8K views45 slides

More Related Content

What's hot

Java Day-4 by
Java Day-4Java Day-4
Java Day-4People Strategists
1.3K views67 slides
Java Day-6 by
Java Day-6Java Day-6
Java Day-6People Strategists
1.7K views57 slides
TMPA-2015: The Application of Parameterized Hierarchy Templates for Automated... by
TMPA-2015: The Application of Parameterized Hierarchy Templates for Automated...TMPA-2015: The Application of Parameterized Hierarchy Templates for Automated...
TMPA-2015: The Application of Parameterized Hierarchy Templates for Automated...Iosif Itkin
3K views24 slides
Reducing Redundancies in Multi-Revision Code Analysis by
Reducing Redundancies in Multi-Revision Code AnalysisReducing Redundancies in Multi-Revision Code Analysis
Reducing Redundancies in Multi-Revision Code AnalysisSebastiano Panichella
526 views65 slides
C# Basic - Lec1 (Workshop on C# Programming: Learn to Build) by
C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)
C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)Jannat Ruma
148 views32 slides
Type Casting C# - Lec4 (Workshop on C# Programming: Learn to Build) by
Type Casting C# - Lec4 (Workshop on C# Programming: Learn to Build)Type Casting C# - Lec4 (Workshop on C# Programming: Learn to Build)
Type Casting C# - Lec4 (Workshop on C# Programming: Learn to Build)Jannat Ruma
120 views11 slides

What's hot(9)

TMPA-2015: The Application of Parameterized Hierarchy Templates for Automated... by Iosif Itkin
TMPA-2015: The Application of Parameterized Hierarchy Templates for Automated...TMPA-2015: The Application of Parameterized Hierarchy Templates for Automated...
TMPA-2015: The Application of Parameterized Hierarchy Templates for Automated...
Iosif Itkin3K views
C# Basic - Lec1 (Workshop on C# Programming: Learn to Build) by Jannat Ruma
C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)
C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)
Jannat Ruma148 views
Type Casting C# - Lec4 (Workshop on C# Programming: Learn to Build) by Jannat Ruma
Type Casting C# - Lec4 (Workshop on C# Programming: Learn to Build)Type Casting C# - Lec4 (Workshop on C# Programming: Learn to Build)
Type Casting C# - Lec4 (Workshop on C# Programming: Learn to Build)
Jannat Ruma120 views
Data Type C# - Lec2 (Workshop on C# Programming: Learn to Build) by Jannat Ruma
Data Type C# - Lec2 (Workshop on C# Programming: Learn to Build)Data Type C# - Lec2 (Workshop on C# Programming: Learn to Build)
Data Type C# - Lec2 (Workshop on C# Programming: Learn to Build)
Jannat Ruma53 views

Similar to Getting Started with C++

C++ Advanced Features by
C++ Advanced FeaturesC++ Advanced Features
C++ Advanced FeaturesMichael Redlich
280 views62 slides
C++ Advanced Features by
C++ Advanced FeaturesC++ Advanced Features
C++ Advanced FeaturesMichael Redlich
96 views62 slides
c++ ppt.ppt by
c++ ppt.pptc++ ppt.ppt
c++ ppt.pptFarazKhan89093
13 views69 slides
lecture02-cpp.ppt by
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.pptMZGINBarwary
14 views69 slides
Getting Started with Java by
Getting Started with JavaGetting Started with Java
Getting Started with JavaMichael Redlich
237 views41 slides
lecture02-cpp.ppt by
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.pptDevliNeeraj
7 views69 slides

Similar to Getting Started with C++(20)

UsingCPP_for_Artist.ppt by vinu28455
UsingCPP_for_Artist.pptUsingCPP_for_Artist.ppt
UsingCPP_for_Artist.ppt
vinu284551 view
.NET and C# Introduction by Siraj Memon
.NET and C# Introduction.NET and C# Introduction
.NET and C# Introduction
Siraj Memon21.4K views
introduction to c # by Sireesh K
introduction to c #introduction to c #
introduction to c #
Sireesh K332 views
Object oriented programming in C++ by jehan1987
Object oriented programming in C++Object oriented programming in C++
Object oriented programming in C++
jehan1987573 views
A simple and powerful property system for C++ (talk at GCDC 2008, Leipzig) by David Salz
A simple and powerful property system for C++ (talk at GCDC 2008, Leipzig)   A simple and powerful property system for C++ (talk at GCDC 2008, Leipzig)
A simple and powerful property system for C++ (talk at GCDC 2008, Leipzig)
David Salz3.6K views
Introduction to Object Oriented Programming & Design Principles by Michael Redlich
Introduction to Object Oriented Programming & Design PrinciplesIntroduction to Object Oriented Programming & Design Principles
Introduction to Object Oriented Programming & Design Principles
Michael Redlich377 views
Migrating from matlab to python by ActiveState
Migrating from matlab to pythonMigrating from matlab to python
Migrating from matlab to python
ActiveState1.2K views

More from Michael Redlich

Getting Started with GitHub by
Getting Started with GitHubGetting Started with GitHub
Getting Started with GitHubMichael Redlich
153 views30 slides
Building Microservices with Micronaut: A Full-Stack JVM-Based Framework by
Building Microservices with Micronaut:  A Full-Stack JVM-Based FrameworkBuilding Microservices with Micronaut:  A Full-Stack JVM-Based Framework
Building Microservices with Micronaut: A Full-Stack JVM-Based FrameworkMichael Redlich
416 views55 slides
Building Microservices with Helidon: Oracle's New Java Microservices Framework by
Building Microservices with Helidon:  Oracle's New Java Microservices FrameworkBuilding Microservices with Helidon:  Oracle's New Java Microservices Framework
Building Microservices with Helidon: Oracle's New Java Microservices FrameworkMichael Redlich
274 views58 slides
Java Advanced Features by
Java Advanced FeaturesJava Advanced Features
Java Advanced FeaturesMichael Redlich
250 views47 slides
Introduction to Object Oriented Programming & Design Principles by
Introduction to Object Oriented Programming & Design PrinciplesIntroduction to Object Oriented Programming & Design Principles
Introduction to Object Oriented Programming & Design PrinciplesMichael Redlich
117 views59 slides
Building Realtime Access to Data Apps with jOOQ by
Building Realtime Access to Data Apps with jOOQBuilding Realtime Access to Data Apps with jOOQ
Building Realtime Access to Data Apps with jOOQMichael Redlich
225 views21 slides

More from Michael Redlich(16)

Building Microservices with Micronaut: A Full-Stack JVM-Based Framework by Michael Redlich
Building Microservices with Micronaut:  A Full-Stack JVM-Based FrameworkBuilding Microservices with Micronaut:  A Full-Stack JVM-Based Framework
Building Microservices with Micronaut: A Full-Stack JVM-Based Framework
Michael Redlich416 views
Building Microservices with Helidon: Oracle's New Java Microservices Framework by Michael Redlich
Building Microservices with Helidon:  Oracle's New Java Microservices FrameworkBuilding Microservices with Helidon:  Oracle's New Java Microservices Framework
Building Microservices with Helidon: Oracle's New Java Microservices Framework
Michael Redlich274 views
Introduction to Object Oriented Programming & Design Principles by Michael Redlich
Introduction to Object Oriented Programming & Design PrinciplesIntroduction to Object Oriented Programming & Design Principles
Introduction to Object Oriented Programming & Design Principles
Michael Redlich117 views
Building Realtime Access to Data Apps with jOOQ by Michael Redlich
Building Realtime Access to Data Apps with jOOQBuilding Realtime Access to Data Apps with jOOQ
Building Realtime Access to Data Apps with jOOQ
Michael Redlich225 views
Building Realtime Access Data Apps with Speedment (TCF ITPC 2017) by Michael Redlich
Building Realtime Access Data Apps with Speedment (TCF ITPC 2017)Building Realtime Access Data Apps with Speedment (TCF ITPC 2017)
Building Realtime Access Data Apps with Speedment (TCF ITPC 2017)
Michael Redlich281 views
Building Realtime Web Apps with Angular and Meteor by Michael Redlich
Building Realtime Web Apps with Angular and MeteorBuilding Realtime Web Apps with Angular and Meteor
Building Realtime Web Apps with Angular and Meteor
Michael Redlich319 views
Java Advanced Features (TCF 2014) by Michael Redlich
Java Advanced Features (TCF 2014)Java Advanced Features (TCF 2014)
Java Advanced Features (TCF 2014)
Michael Redlich754 views
Introduction to Object-Oriented Programming & Design Principles (TCF 2014) by Michael Redlich
Introduction to Object-Oriented Programming & Design Principles (TCF 2014)Introduction to Object-Oriented Programming & Design Principles (TCF 2014)
Introduction to Object-Oriented Programming & Design Principles (TCF 2014)
Michael Redlich2.4K views
Getting Started with Meteor (TCF ITPC 2014) by Michael Redlich
Getting Started with Meteor (TCF ITPC 2014)Getting Started with Meteor (TCF ITPC 2014)
Getting Started with Meteor (TCF ITPC 2014)
Michael Redlich902 views
Getting Started with Java (TCF 2014) by Michael Redlich
Getting Started with Java (TCF 2014)Getting Started with Java (TCF 2014)
Getting Started with Java (TCF 2014)
Michael Redlich777 views
C++ Advanced Features (TCF 2014) by Michael Redlich
C++ Advanced Features (TCF 2014)C++ Advanced Features (TCF 2014)
C++ Advanced Features (TCF 2014)
Michael Redlich1.4K views
Getting Started with MongoDB (TCF ITPC 2014) by Michael Redlich
Getting Started with MongoDB (TCF ITPC 2014)Getting Started with MongoDB (TCF ITPC 2014)
Getting Started with MongoDB (TCF ITPC 2014)
Michael Redlich2.2K views

Recently uploaded

Playwright Retries by
Playwright RetriesPlaywright Retries
Playwright Retriesartembondar5
7 views1 slide
How To Make Your Plans Suck Less — Maarten Dalmijn at the 57th Hands-on Agile... by
How To Make Your Plans Suck Less — Maarten Dalmijn at the 57th Hands-on Agile...How To Make Your Plans Suck Less — Maarten Dalmijn at the 57th Hands-on Agile...
How To Make Your Plans Suck Less — Maarten Dalmijn at the 57th Hands-on Agile...Stefan Wolpers
44 views38 slides
Ports-and-Adapters Architecture for Embedded HMI by
Ports-and-Adapters Architecture for Embedded HMIPorts-and-Adapters Architecture for Embedded HMI
Ports-and-Adapters Architecture for Embedded HMIBurkhard Stubert
35 views19 slides
How Workforce Management Software Empowers SMEs | TraQSuite by
How Workforce Management Software Empowers SMEs | TraQSuiteHow Workforce Management Software Empowers SMEs | TraQSuite
How Workforce Management Software Empowers SMEs | TraQSuiteTraQSuite
7 views3 slides
FOSSLight Community Day 2023-11-30 by
FOSSLight Community Day 2023-11-30FOSSLight Community Day 2023-11-30
FOSSLight Community Day 2023-11-30Shane Coughlan
8 views18 slides
Page Object Model by
Page Object ModelPage Object Model
Page Object Modelartembondar5
7 views5 slides

Recently uploaded(20)

How To Make Your Plans Suck Less — Maarten Dalmijn at the 57th Hands-on Agile... by Stefan Wolpers
How To Make Your Plans Suck Less — Maarten Dalmijn at the 57th Hands-on Agile...How To Make Your Plans Suck Less — Maarten Dalmijn at the 57th Hands-on Agile...
How To Make Your Plans Suck Less — Maarten Dalmijn at the 57th Hands-on Agile...
Stefan Wolpers44 views
Ports-and-Adapters Architecture for Embedded HMI by Burkhard Stubert
Ports-and-Adapters Architecture for Embedded HMIPorts-and-Adapters Architecture for Embedded HMI
Ports-and-Adapters Architecture for Embedded HMI
Burkhard Stubert35 views
How Workforce Management Software Empowers SMEs | TraQSuite by TraQSuite
How Workforce Management Software Empowers SMEs | TraQSuiteHow Workforce Management Software Empowers SMEs | TraQSuite
How Workforce Management Software Empowers SMEs | TraQSuite
TraQSuite7 views
FOSSLight Community Day 2023-11-30 by Shane Coughlan
FOSSLight Community Day 2023-11-30FOSSLight Community Day 2023-11-30
FOSSLight Community Day 2023-11-30
Shane Coughlan8 views
Top-5-production-devconMunich-2023-v2.pptx by Tier1 app
Top-5-production-devconMunich-2023-v2.pptxTop-5-production-devconMunich-2023-v2.pptx
Top-5-production-devconMunich-2023-v2.pptx
Tier1 app9 views
aATP - New Correlation Confirmation Feature.pptx by EsatEsenek1
aATP - New Correlation Confirmation Feature.pptxaATP - New Correlation Confirmation Feature.pptx
aATP - New Correlation Confirmation Feature.pptx
EsatEsenek1222 views
How to build dyanmic dashboards and ensure they always work by Wiiisdom
How to build dyanmic dashboards and ensure they always workHow to build dyanmic dashboards and ensure they always work
How to build dyanmic dashboards and ensure they always work
Wiiisdom16 views
Transport Management System - Shipment & Container Tracking by Freightoscope
Transport Management System - Shipment & Container TrackingTransport Management System - Shipment & Container Tracking
Transport Management System - Shipment & Container Tracking
Freightoscope 6 views
JioEngage_Presentation.pptx by admin125455
JioEngage_Presentation.pptxJioEngage_Presentation.pptx
JioEngage_Presentation.pptx
admin1254559 views
Automated Testing of Microsoft Power BI Reports by RTTS
Automated Testing of Microsoft Power BI ReportsAutomated Testing of Microsoft Power BI Reports
Automated Testing of Microsoft Power BI Reports
RTTS11 views
Supercharging your Python Development Environment with VS Code and Dev Contai... by Dawn Wages
Supercharging your Python Development Environment with VS Code and Dev Contai...Supercharging your Python Development Environment with VS Code and Dev Contai...
Supercharging your Python Development Environment with VS Code and Dev Contai...
Dawn Wages5 views
Bootstrapping vs Venture Capital.pptx by Zeljko Svedic
Bootstrapping vs Venture Capital.pptxBootstrapping vs Venture Capital.pptx
Bootstrapping vs Venture Capital.pptx
Zeljko Svedic16 views
predicting-m3-devopsconMunich-2023.pptx by Tier1 app
predicting-m3-devopsconMunich-2023.pptxpredicting-m3-devopsconMunich-2023.pptx
predicting-m3-devopsconMunich-2023.pptx
Tier1 app10 views

Getting Started with C++

  • 1. 1 Getting Started with C++ Trenton Computer Festival March 17, 2018 Michael P. Redlich @mpredli about.me/mpredli/
  • 2. Who’s Mike? • BS in CS from • “Petrochemical Research Organization” • Java Queue News Editor, InfoQ • Ai-Logix, Inc. (now AudioCodes) • Amateur Computer Group of New Jersey 2
  • 3. Objectives (1) • What is C++? • Evolution of C++ • Features of C++ • Review of Object-Oriented Programming (OOP) 3
  • 4. Objectives (2) • Getting Started with C++ • introduction to the C++ class mechanism • how to implement C++ classes • Live Demos (yea!) • C++ Resources 4
  • 5. What is C++? • “...a general purpose programming language with a bias towards systems programming that • is a better C, • supports data abstraction, • supports object-oriented programming, • supports generic programming.” Bjarne Stroustrup Web Site, http://www.stroustrup.com/C++.html 5
  • 6. Evolution of C++ (1) • Created by Bjarne Stroustrup • AT&T Labs • 1980 - originally named “C with Classes” • 1983 - redesigned and renamed to C++ • 1985 - available to the public 6
  • 7. Evolution of C++ (2) • 1989 - further extensions added • templates and exception handling • 1998 - C++ standardized 7
  • 8. Features of C++ • Object-Oriented Programming (OOP) Language • Pass-by-Reference • Operator Overloading • Generic Programming • Exception Handling • Namespaces • Default Arguments 8
  • 9. OOP Review (1) • Programming Paradigm • Four (4) Main Attributes • data encapsulation • data abstraction • inheritance • polymorphism 9
  • 10. OOP Review (2) • Abstract Data Type (ADT) • user-defined data type • use of objects through functions (methods) without knowing the internal representation 10
  • 11. OOP Review (3) • Interface • functions (methods) provided in the ADT that allow access to data • Implementation • underlying data structure(s) and business logic within the ADT 11
  • 12. OOP Review (4) • Class • Defines a model • Declares attributes • Declares behavior • Is an ADT • Object • Is an instance of a class • Has state • Has behavior • May have many unique objects of the same class 12
  • 13. Advantages of OOP • Interface can (and should) remain unchanged when improving implementation • Encourages modularity in application development • Better maintainability of code • Code reuse • Emphasis on what, not how 13
  • 14. Some C++ Keywords • class • new, delete • private, protected, public • try, throw, catch • friend • explicit • virtual • bool • inline 14
  • 15. Classes (1) • A user-defined abstract data type • Extension of C structs • Contain: • constructor • destructor • data members and member functions (methods) 15
  • 16. Classes (2) • Static/Dynamic object instantiation • Multiple Constructors: • Sports(void); • Sports(char *,int,int); • Sports(float,char *,int); 16
  • 17. Classes (3) • Class scope: • scope resolution operator(::) • Abstract Classes • contain at least one pure virtual member function (C++) • contain at least one abstract method (Java) 17
  • 18. Abstract Classes • Pure virtual member function (C++) • virtual void draw() = 0; • Abstract method (Java) • public abstract void draw(); 18
  • 20. 20 // Sports class (partial listing) class Sports { private: char *team; int win; public: Sports(void); Sports(char const *,int,int); ~Sports(void); // destructor int getWin() const; }; Sports::Sports(void) { // define default constructor here... } Sports::Sports(const char *team,int win,int loss) { // define primary constructor here... } int Sports::getWin() const { return win; }
  • 21. 21 // Baseball class (partial listing) class Baseball : public Sports { public: Baseball(void); Baseball(char const *,int,int); ~Baseball(void); }; Baseball::Baseball(void) : Sports() { } Baseball::Baseball(const char *team,int win,int loss) : Sports(team,win,loss) { } inline Baseball::~Baseball(void) { }
  • 22. Static Instantiation • Object creation: • Baseball mets(“Mets”,97,65); • Access to public member functions: • mets.getWin(); // returns 97 22
  • 23. Dynamic Instantiation • Object creation: • Baseball *mets = new Baseball(“Mets”,97,65); • Access to public member functions: • mets->getWin(); // returns 97 23
  • 24. Deleting Objects Baseball mets(“Mets”,97,65); // object deleted when out of scope Baseball *mets = new Baseball(“Mets”,97,65); delete mets; // required call 24
  • 25. Operator new (1) • Allocates memory on the free store (heap) • Memory size is calculated by the compiler • No more casting • Automatic call to the constructor • Used for built-in and user-defined data types 25
  • 26. Operator new (2) int *var = new int; // int(); Sports *sports = new Sports(); // initializes an array of pointers to type int int *var = new int[10] 26
  • 27. Operator delete (1) • Deallocates memory on the free store (heap) • Automatic call to the destructor • Must be used according to how operator new was used 27
  • 28. Operator delete (2) int *var = new int; delete var; int *var = new int[10] delete[] var; 28
  • 29. Inline Member Functions (1) • Used for short functions (≤ 5 statements) • Purpose: • speed • Good candidates for inline member functions are those that access data members 29
  • 30. Inline Member Functions (2) • Explicit Use: • use keyword inline in the definition of member function • Implicit Use: • define the member function within its declaration without using the keyword inline 30
  • 32. Popular C++ Compilers 32 • Embarcadero C++ Builder XE7 • embarcadero.com/products/cbuilder • MicrosoftVisual C++ • microsoft.com • Intel System Studio • software.intel.com/en-us/c- compilers
  • 33. Popular C++ Compilers 33 • Open Watcom 1.9 (June 2010) • openwatcom.org
  • 34. Local C++ User Groups • ACGNJ C++ Users Group • facilitated by Bruce Arnold • acgnj.barnold.us 34
  • 35. Further Reading (1) 35 • C & C++ Code Capsules • Chuck Allison • freshsources.com • The C++ Programming Language • Bjarne Stroustrup • stroustrup.com/4th.html
  • 36. Further Reading (2) 36 • The Annotated C++ Reference Manual • Margaret Ellis and Bjarne Stroustrup • stroustrup.com/arm.html • 1997 C++ Public Review Document • C++ ISO JTC1/SC22/WG21 Committee • open-std.org/jtc1/sc22/open/n2356
  • 37. Upcoming Events • ACGNJ Java Users Group • Dr. Venkat Subramaniam • Monday, March 19, 2018 • DorothyYoung Center for the Arts, Room 106 • Drew University • 7:30-9:00pm • “Twelve Ways to Make Code Suck Less” 37
  • 39. Upcoming Events • March 17-18, 2017 •tcf-nj.org • April 18-19, 2017 •phillyemergingtech.com 39