... IntArray B (100); // IntArray with 100 elements, each initialized to 0

Size: px
Start display at page:

Download "... IntArray B (100); // IntArray with 100 elements, each initialized to 0"

Transcription

1 Types with External Resources A class constructor is invoked when an object comes into scope. The constructor prepares the object by creating an environment in which the member functions operate. For many classes, including the Date example, there are no issues when an object of that type goes out of scope or a copy of the object is required. The simple compiler-generated decomissioning of objects and making copys of objects suffices. We refer to these processes as the compiler-generated default versions of destructor, copy constructor, and assignment operator. However, there are classes for which specific "decomissioning" of objects is necessary when an object goes out of scope and where a careful class-specific procedure must be followed when copying objects. When the environment created by a constructor acquires some resource (external to the object), that resource must be released when the object goes out of scope. Typical resources in this category are: 1. Dynamically allocated memory 2. An open file 3. A lock on some external object Of these, the first is the most common and the one we will concentrate on here. Destructor Consider the following: // more later ; We will fill in other member functions and even operators later in this chapter, but now concentrate on the constructor. The intended use of IntArray is to build arrays of type int as objects which can be declared and used as if they were native types. The constructor should therefore create an array (lower case, meaning "Cstyle array") of the appropriate size and initialize all of the elements. Its implementation would go something like the following: IntArray::IntArray (size_t size, int ivalue) : size_(size) data_ = new int [size_]; if (data_ == 0) // check for failed memory allocation std::cerr << "** Memory allocation for IntArray failed - aborting program\n"; exit (1); for (size = 0; size < size_; ++size) data_[size] = ivalue; Objects would be created by client programs as if they were native types, for example: IntArray A (1000, -1); // IntArray with 1000 elements, each initialized to -1 IntArray B (100); // IntArray with 100 elements, each initialized to 0 IntArray C; // IntArray dynamically of default size and initialized to 0 1/13

2 In each case, the constructor for IntArray has created an object with dynamically allocated memory associated with it. When the object goes out of scope, this memory allocation must be returned to the system. The client program has no way to do this explicitly, and furthermore should not have that responsibility. The memory de-allocation should be handled by the class destructor, prototyped in color below: // more later The method whose name is the class name preceded by ~ is the destructor. The class destructor is called automatically for each object as it goes out of scope. In the case of IntArray, a simple call to operator delete[] will suffice: IntArray::~IntArray () delete [] data_; This will ensure that memory allocated for the object is properly de-allocated. Copy Constructor There are two situations when an object is copied implictly 1. When an object is passed to a function as a value parameter 2. When an object is returned by a function as a value In each of these cases, a copy is made implicitly by the compiler: in the first case this copy is the local variable of the function defined by the parameter, and in the second case the copy is the value returned to the calling process by the function. In either case, the object is being created as a copy of an existing object. The compiler calls the copy constructor to create these objects. For example, given this function prototype and call: IntArray Fun (IntArray a); // prototype IntArray a,b; b = Fun(a); // copy of argument "a" made when function is called // copy of return value made as function returns Note that a copy of a must be made for Fun to have as a local variable and then a copy of the return value of Fun must be made at the point of return. In addition a copy must be made explictly when one object is used to initialize another, as in: IntArray a; IntArray b(a); // explicit call to copy constructor - make "b" a copy of "a" The compiler will generate code to copy the memory footprint of objects, unless a copy constructor is given in the class definition, in which case the copy constructor will be called. (If the copy constructor prototype is private, a compile error is generated by code like the above.) 2/13

3 A copy constructor for our IntArray class is highlighted in the following expanded class definition: // more later ; An implementation for this copy constructor is as follows: IntArray::IntArray (const IntArray& a) : size_(a.size_) data_ = new int [size_]; // check for failed allocation data_[i] = a.data_[i]; If there is no copy constructor defined for a class, the compiler will simply make a raw memory copy of the object. Clearly, when there are dynamically allocated resources owned by the object, that approach will not be satisfactory and a copy constructor must be supplied explicitly. Self-Reference There are times when implementation of a class member function need to refer to the object itself, the one for which the method is being implemented. The keyword this contains the address of the object and can be used to access the location of the object as well as the object itself through pointer dereference. // context/scope: implementation of a member function this // pointer to the current object *this // the actual object Self-reference is particularly necessary to define an assignment operator. Assignment Operator Assignment is an operator. Recall that it (like all operators) has operator function notation with the same meaning. For example, if a and b are objects of the same type in a client program, assignment of b to a can be done with either syntax: a = b; // operator notation a.operator=(b); // operator function notation The latter seems a bit clumsy, but it does have the advantage of clarifying exactly what role various things play. For example, it is clear that operator= is a member operator of a, the object on the left, and it takes as argument the object b on the right. Operator function notation is also used when prototyping and implementing operators. Recall also that assignment associates right to left, so that statements like a = b = c; 3/13

4 are meaningful and do the appropriate thing, namely a = (b = c); Assignment must return a reference to the calling object in order for the successive call to have the correct input argument. Taking these observations into account allows us to write the prototype for assignment in our IntArray class: ; The right-hand argument (named b in the prototype) is the object to be copied, so we can guarantee that it is unchanged during the call to operator=. The basic task for assignment is similar to that solved by the copy constructor, and we can even re-use some of the code for implemention. Here is a first attempt: IntArray& IntArray::operator =(const IntArray& b) size_ = b.size_; data_ = new int [size_]; // check for failed allocation data_[i] = b.data_[i]; return *this; where the only difference is the addition of the line that returns the object (by reference, which is determined by the return type). There is one important distinction between the circumstances in which a copy constructor is called and when an assignment operator is called, however. The copy constructor is called implicitly, and always for a new object that is under construction, such as am argument for a function call or a function return value. Assignment is typically explicitly called in client programs, and usually the object on the left is not newly created but is being re-defined. In the case of IntArray objects, this means that the array data_ will already have been defined. This memory is orphaned by the second line of code in the above implementation. The fix for this problem is to first delete the old memory, as in the following revision: IntArray& IntArray::operator =(const IntArray& b) delete [] data_; size_ = b.size_; data_ = new int [size_]; // check for failed allocation data_[i] = b.data_[i]; return *this; Now we have ensured that memory associated with the left hand side is correctly released before it is lost. There is one remaining problem, however: what if the client has made a an alias for b and then makes the call a = b? The code above would be a disaster, deleting the very memory that is to be copied, thus losing the client's precious information. The fix for this problem is to check for self-assignment and do nothing in 4/13

5 that case (after all, when a and b are the same object, there is nothing to be accomplished by a = b). IntArray& IntArray::operator =(const IntArray& b) if (this!= &b) delete [] data_; size_ = b.size_; data_ = new int [size_]; // check for failed allocation data_[i] = b.data_[i]; return *this; The pattern illustrated above may be followed by all overloads of the assignment operator. Proper Types A type is called proper under any of these circumstances: 1. It is a native type. 2. It is a class with constructor, destructor, copy constructor, and assignment operator that manage the type as if it were a native type. 3. It is a user defined type (class) whose variables are proper types. Note that the effect of being proper type is that client programs can use the type exactly as if it were a native type, without any concerns about resource management for the objects. IntArray A; // IntArray with default number of elements IntArray B(100); // IntArray with 100 elements IntArray C(100,-1); // IntArray with 100 elements each initialized to -1 B = A; A = B = C; // destructor for each object A, B, C is called as they go out of scope Objects of type IntArray are declared, at which time memory is allocated. The may be assigned or reassigned without concern over memory management; and when they go out of scope the destructor is called. From the client's perspective, IntArray objects can be handled as easily as type int objects. Constant Member Functions The keyword const may be applied to member functions (or member operators). The meaning is that the object will not be changed when that method is invoked. This is a guarantee that is enforced by the compiler. 5/13

6 size_t Size() const; ; We have promised that the method Size() will not change the calling object. We follow through by implementing the method without any change of state of the calling object: size_t IntArray::Size() const return size_; Note that const methods are distinct from non-const methods by the same name. In particular, if the keyword const is applied to either the prototype or the implementation of a method, it must be applied to both. Operator Overloading Member operators and non-member (stand-alone) operators may be overloaded for a particular class. The following adds the bracket operator (a class member) and the output operator (not a class member) to the interface of IntArray: size_t Size() const; int& operator [] (size_t i); // member operator const int& operator [] (size_t i) const; // const version ; std::ostream& operator << (std::ostream& os, const IntArray& A); // stand-alone operator These are implemented as follows: int& IntArray::operator [] (size_t i) return *(data_ + i); const int& IntArray::operator [] (size_t i) const return *(data_ + i); std::ostream& operator << (std::ostream& os, const IntArray& A) for (size_t i = 0; i < A.Size() - 1; ++i) os << A[i] << ' '; os << A[A.Size() - 1] << '\n'; return os; 6/13

7 The bracket operator is required to be a member of the class - a requirement that makes sense since the implementation of this operator, like the copy constructor, must depend on the most intimate details of the class design. On the other hand, the following analysis shows why the I/O operators cannot be class members. Begin with the fact that a member operator always has the object making the call as the "implicit" first argument, as illustrated in the discussion of the assignment operator earlier in this chapter. The I/O operators, on the other hand, always have a stream object as the first parameter. Therefore it can't work out to make the I/O operators class member operatots, these must be stand-alone. In-Class Function Definitions Class member functions may be implemented within the class definition, as in this example: size_t Size() const return size_; int& operator [] (size_t i) return *(data_ + i); const int& operator [] (size_t i) const return *(data_ + i); ; Any advantage of in-class implementation comes in the form of easing of human suffering - it may make the class definition easier to read (dubious) and it may make the class easier to implement (of questionable value, unless all methods are implemented in-class, for otherwise the separation of implementations into separate places creates a code readability/maintenance problem). In-line implementation does not force the compiler to write more efficient code, although it is usually taken as a suggestion to in-line the code. Dynamic Objects Because objects created with operator new have global scope, and often the pointers used to locate these objects have local scope, the question is, when does the destructor get called? Here is some sample client code: // run time bindings IntArray * xptr, * yptr, * zptr; // pointers to type IntArray IntArray * Aptr = new IntArray(); // ptr to default IntArray object IntArray * Bptr = new IntArray(100); // ptr to 100-element IntArray object IntArray * Cptr = new IntArray(100,-1); // ptr to 100-element IntArray object 7/13

8 // Note that IntArray constructors are called as operator new is invoked xptr = Aptr; // simple assignment of integer type (addresses) yptr = Bptr; // simple assignment of integer type zptr = Cptr; // simple assignment of integer type // Note that Aptr, Bptr, Cptr go out of scope here, but // objects they point to are global scope and STILL EXIST delete xptr; // IntArray object goes out of scope, destructor called delete yptr; // IntArray object goes out of scope, destructor called delete zptr; // IntArray object goes out of scope, destructor called The destructor is called implicitly with operator delete Accessing Members: Dot and Arrow Notation As mentioned earlier, objects access public members (member variables and member functions) using the dot notation, as in this example: IntArray A, B; // create objects A and B of type IntArray A.Size(); // object A accesses the member function Size() B.Size(); // object B accesses the member function Size() For pointers to objects, the pointer must first be de-referenced (using operator *) and then a member function can be accessed (using operator.). Because the resulting accumulation of operator evaluations can become cumbersome and unsightly, an alternative notation allows access of a member variable or function directly from the pointer, using the arrow operator ->, as in the following example: IntArray A; // create IntArray object IntArray *Aptr; // create pointer to type IntArray Aptr = new IntArray; // create IntArray object at address Aptr A.Size(); // object A accesses member function Size() (*Aptr).Size(); // object *Aptr accesses member function Size() Aptr -> Size(); // access member function through pointer The last two lines of code have identical meaning. Note that the parentheses surrounding *Aptr are necessary, because the dot operator has higher precedence than the star operator. Static Member Variables The keyword static, inherited from C, retains its C meaning but also adds some semantics in the context of classes. The principle is that static associates with the class itself instead of with specific objects of the class. It may seem surprising that data may be associated with a class instead of one of its objects, but a simple (albeit somewhat contrived) example shows how this can be useful: size_t Size() const; int& operator [] (size_t i); const int& operator [] (size_t i) const; 8/13

9 static unsigned int objectcount_; // the number of objects currently in existence ; The data item objectcount_ will keep a running tally of the number of objects of the class in existence at any given moment in a running program. For this to work, we have to make sure that objectcount_ is initialized to zero before any objects are cteated and then add increment/decrement code to the constructor/destructor: unsigned int IntArray::objectCount_ = 0; IntArray::IntArray (size_t size, ivalue) : size_(size) data_ = new(std::nothrow) int [size_]; if (data_ == 0) // check for failed memory allocation std::cerr << "** Memory allocation for IntArray failed - aborting program\n"; exit (1); data_[i] = ivalue; ++objectcount_; IntArray::~IntArray () delete [] data_; --objectcount_; The number of objects can be useful, in applicatons (for example, keeping a running count of the number of records created in a database), in making efficient implementatons (for example, keepiong only one actual copy of large objects and letting all other instances point to this one), and in program correctness (where the object count can be tested, for example it should be zero at certain benchmarl locations in a text client). Static Member Functions A static member function is one that can be called from the class level (with no objects created) or from any object. Because it is not associated with any object, a static method may not access non-static data in an object, but it may access static class data. A typical use would be to access private static data: size_t Size() const; int& operator [] (size_t i); const int& operator [] (size_t i) const; static unsigned int ObjectCount () const; static unsigned int objectcount_; ; 9/13

10 unsigned int IntArray::ObjectCount () const return objectcount_; A static method that does not access any (static) class data is effectively a stand-alone function whose scope is restricted to the class scope. Here is an example, where the allocation of memory and error checking is captured in one private static member function that can be called by various other method implementations such as constructors and assignment: size_t Size() const; int& operator [] (size_t i); const int& operator [] (size_t i) const; static int* NewArray (size_t size); ; int* IntArray::NewArray (size_t size) int * ptr = new(std::nothrow) int [size]; if (ptr == 0) std::cerr << "** Allocation failure in - aborting execution\n"; exit (1); return ptr; The method NewArray is a "helper" function that encapsulates a repetitive housekeeping task into one place where it can be maintained. This makes all of the other method implementations that use dynamic memory easier to read, and it means that the policy for handling a failed aloocation can be changed in one place while ensuring consistent adherence to the policy. Mutable Member Variables A member variable may be declared mutable, which means that even when the object is constant or a const member function is called, the mutable member variable is allowed to change. The use of mutable variables should be restricted to cases where the "logical constness" of the object is not affected by that variable. Here is a contrived example using the class Date from the previous chapter: Taking all these ideas into account, keeping some and discarding others, we come up with a fairly useful and not bloated storage class for tucking away when we need arrays again. We also organize the code into the usual header/implementation file pair, and include a short test client program. First the header file: 10/13

11 /* intarray.h */ definition of the IntArray class and interface #ifndef _INTARRAY_H // morph of the file name into a legal indentifier #define _INTARRAY_H #include <cstdlib> #include <iostream> // note formatting for self-documentation IntArray& operator = (const IntArray& b); size_t Size () const; int& operator [] (size_t i); const int& operator [] (size_t i) const; // class variables // member function static int* NewArray (size_t size); ; std::ostream& operator << (std::ostream& os, const IntArray& A); #endif Second the implementaton file: /* IntArray.cpp */ implenentation of IntArray methods and operators #include <intarray.h> IntArray::IntArray ( size_t size, int ivalue ) : size_(size), data_(0) data_ = NewArray(size_); data_[i] = ivalue; IntArray::~IntArray () delete [] data_; IntArray::IntArray (const IntArray& a) : size_(a.size_), data_(0) data_ = NewArray(size_); data_[i] = a.data_[i]; IntArray& IntArray::operator =(const IntArray& b) if (this!= &b) 11/13

12 delete [] data_; size_ = b.size_; data_ = NewArray(size_); data_[i] = b.data_[i]; return *this; size_t IntArray::Size() const return size_; int& IntArray::operator [] (size_t i) return *(data_ + i); const int& IntArray::operator [] (size_t i) const return *(data_ + i); std::ostream& operator << (std::ostream& os, const IntArray& A) for (size_t i = 0; i < A.Size() - 1; ++i) os << A[i] << ' '; os << A[A.Size() - 1] << '\n'; return os; int* IntArray::NewArray (size_t size) int * ptr = new(std::nothrow) int [size]; if (ptr == 0) std::cerr << "** Allocation failure in - aborting execution\n"; exit (1); return ptr; Third a simple test client: /* test client for IntArray */ #include <intarray.h> #include <iostream> int main() IntArray a; IntArray b(20); IntArray c(30, -1); int num; size_t count; std::cout << "Data in IntArray a: " << a << "Data in IntArray b: " << b << "Data in IntArray c: " << c; std::cout << "Enter integer data: "; for (count = 0; std::cin >> num && count < a.size(); ++count) 12/13

13 a[count] = num; std::cout << "Data in IntArray a: " << a; c = b = a; std::cout << "Data in IntArray b: " << b; std::cout << "Data in IntArray c: " << c; Exercise: Create these three files, compile and test. 13/13

Object Oriented Design

Object Oriented Design Object Oriented Design Chapter 9 Initializing a non-static data member in the class definition is a syntax error 1 9.2 Time Class Case Study In Fig. 9.1, the class definition is enclosed in the following

More information

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor. 3.Constructors and Destructors Develop cpp program to implement constructor and destructor. Constructors A constructor is a special member function whose task is to initialize the objects of its class.

More information

Operator Overloading in C++ Systems Programming

Operator Overloading in C++ Systems Programming Operator Overloading in C++ Systems Programming Operator Overloading Fundamentals of Operator Overloading Restrictions on Operator Overloading Operator Functions as Class Members vs. Global Functions Overloading

More information

Operator overloading

Operator overloading 1 Introduction 2 The copy constructor 3 Operator Overloading 4 Eg 1: Adding two vectors 5 The -> operator 6 The this pointer 7 Overloading = 8 Unary operators 9 Overloading for the matrix class 10 The

More information

Fast Introduction to Object Oriented Programming and C++

Fast Introduction to Object Oriented Programming and C++ Fast Introduction to Object Oriented Programming and C++ Daniel G. Aliaga Note: a compilation of slides from Jacques de Wet, Ohio State University, Chad Willwerth, and Daniel Aliaga. Outline Programming

More information

calling a function - function-name(argument list); y = square ( z ); include parentheses even if parameter list is empty!

calling a function - function-name(argument list); y = square ( z ); include parentheses even if parameter list is empty! Chapter 6 - Functions return type void or a valid data type ( int, double, char, etc) name parameter list void or a list of parameters separated by commas body return keyword required if function returns

More information

Chapter 18 - C++ Operator Overloading

Chapter 18 - C++ Operator Overloading Chapter 18 - C++ Operator Overloading Outline 18.1 Introduction 18.2 Fundamentals of Operator Overloading 18.3 Restrictions on Operator Overloading 18.4 Operator Functions as Class Members vs. as friend

More information

Classes: A Deeper Look

Classes: A Deeper Look Classes: A Deeper Look 1 Introduction Implementing a Time Abstract Data Type with a class Class Scope and Accessing Class Members Separating Interface from Implementation Controlling Access to Members

More information

KOM3191 Object Oriented Programming Dr Muharrem Mercimek OPERATOR OVERLOADING. KOM3191 Object-Oriented Programming

KOM3191 Object Oriented Programming Dr Muharrem Mercimek OPERATOR OVERLOADING. KOM3191 Object-Oriented Programming KOM3191 Object Oriented Programming Dr Muharrem Mercimek 1 OPERATOR OVERLOADING KOM3191 Object-Oriented Programming KOM3191 Object Oriented Programming Dr Muharrem Mercimek 2 Dynamic Memory Management

More information

nptr = new int; // assigns valid address_of_int value to nptr std::cin >> n; // assigns valid int value to n

nptr = new int; // assigns valid address_of_int value to nptr std::cin >> n; // assigns valid int value to n Static and Dynamic Memory Allocation In this chapter we review the concepts of array and pointer and the use of the bracket operator for both arrays and pointers. We also review (or introduce) pointer

More information

COMP26120: Pointers in C (2018/19) Lucas Cordeiro

COMP26120: Pointers in C (2018/19) Lucas Cordeiro COMP26120: Pointers in C (2018/19) Lucas Cordeiro lucas.cordeiro@manchester.ac.uk Organisation Lucas Cordeiro (Senior Lecturer, FM Group) lucas.cordeiro@manchester.ac.uk Office: 2.44 Office hours: 10-11

More information

Chapter 13: Copy Control. Overview. Overview. Overview

Chapter 13: Copy Control. Overview. Overview. Overview Chapter 13: Copy Control Overview The Copy Constructor The Assignment Operator The Destructor A Message-Handling Example Managing Pointer Members Each type, whether a built-in or class type, defines the

More information

III. Classes (Chap. 3)

III. Classes (Chap. 3) III. Classes III-1 III. Classes (Chap. 3) As we have seen, C++ data types can be classified as: Fundamental (or simple or scalar): A data object of one of these types is a single object. int, double, char,

More information

Cpt S 122 Data Structures. Introduction to C++ Part II

Cpt S 122 Data Structures. Introduction to C++ Part II Cpt S 122 Data Structures Introduction to C++ Part II Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Topics Objectives Defining class with a member function

More information

Object-Oriented Design (OOD) and C++

Object-Oriented Design (OOD) and C++ Chapter 2 Object-Oriented Design (OOD) and C++ At a Glance Instructor s Manual Table of Contents Chapter Overview Chapter Objectives Instructor Notes Quick Quizzes Discussion Questions Projects to Assign

More information

by Pearson Education, Inc. All Rights Reserved.

by Pearson Education, Inc. All Rights Reserved. Let s improve the bubble sort program of Fig. 6.15 to use two functions bubblesort and swap. Function bubblesort sorts the array. It calls function swap (line 51) to exchange the array elements array[j]

More information

ECE 2400 Computer Systems Programming Fall 2017 Topic 4: C Pointers

ECE 2400 Computer Systems Programming Fall 2017 Topic 4: C Pointers ECE 2400 Computer Systems Programming Fall 2017 Topic 4: C Pointers School of Electrical and Computer Engineering Cornell University revision: 2017-09-23-11-06 1 Pointer Basics 2 2 Call by Value vs. Call

More information

See the CS 2704 notes on C++ Class Basics for more details and examples. Data Structures & OO Development I

See the CS 2704 notes on C++ Class Basics for more details and examples. Data Structures & OO Development I Polynomial Class Polynomial(); Polynomial(const string& N, const vector& C); Polynomial operator+(const Polynomial& RHS) const; Polynomial operator-(const Polynomial& RHS) const; Polynomial operator*(const

More information

Ch. 12: Operator Overloading

Ch. 12: Operator Overloading Ch. 12: Operator Overloading Operator overloading is just syntactic sugar, i.e. another way to make a function call: shift_left(42, 3); 42

More information

Introduction to C++ Systems Programming

Introduction to C++ Systems Programming Introduction to C++ Systems Programming Introduction to C++ Syntax differences between C and C++ A Simple C++ Example C++ Input/Output C++ Libraries C++ Header Files Another Simple C++ Example Inline Functions

More information

Introduction Of Classes ( OOPS )

Introduction Of Classes ( OOPS ) Introduction Of Classes ( OOPS ) Classes (I) A class is an expanded concept of a data structure: instead of holding only data, it can hold both data and functions. An object is an instantiation of a class.

More information

Bits and Bytes. Bit Operators in C/C++

Bits and Bytes. Bit Operators in C/C++ Bits and Bytes The byte is generally the smallest item of storage that is directly accessible in modern computers, and symbiotically the byte is the smallest item of storage used by modern programming

More information

COMP6771 Advanced C++ Programming

COMP6771 Advanced C++ Programming 1.... COMP6771 Advanced C++ Programming Week 3 Part One: - Overview, and 2016 www.cse.unsw.edu.au/ cs6771 2.... What is Object-based Programming? A class uses data abstraction and encapsulation to define

More information

Lecture 18 Tao Wang 1

Lecture 18 Tao Wang 1 Lecture 18 Tao Wang 1 Abstract Data Types in C++ (Classes) A procedural program consists of one or more algorithms that have been written in computerreadable language Input and display of program output

More information

04-19 Discussion Notes

04-19 Discussion Notes 04-19 Discussion Notes PIC 10B Spring 2018 1 Constructors and Destructors 1.1 Copy Constructor The copy constructor should copy data. However, it s not this simple, and we need to make a distinction here

More information

Object-Oriented Principles and Practice / C++

Object-Oriented Principles and Practice / C++ Object-Oriented Principles and Practice / C++ Alice E. Fischer September 26, 2016 OOPP / C++ Lecture 4... 1/33 Global vs. Class Static Parameters Move Semantics OOPP / C++ Lecture 4... 2/33 Global Functions

More information

Instantiation of Template class

Instantiation of Template class Class Templates Templates are like advanced macros. They are useful for building new classes that depend on already existing user defined classes or built-in types. Example: stack of int or stack of double

More information

Lecture 05 POINTERS 1

Lecture 05 POINTERS 1 Lecture 05 POINTERS 1 Pointers Powerful, but difficult to master Simulate call-by-reference Close relationship with arrays and strings Pointer Variable vs. Normal Variable Normal variables contain a specific

More information

Programming in C ++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Programming in C ++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Programming in C ++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture 27 Copy Constructor and Copy Assignment Operator (Contd.) Welcome

More information

Introduction to Programming session 24

Introduction to Programming session 24 Introduction to Programming session 24 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2010 These slides are created using Deitel sslides Sharif Universityof Technology Outlines Introduction

More information

ADTs in C++ In C++, member functions can be defined as part of a struct

ADTs in C++ In C++, member functions can be defined as part of a struct In C++, member functions can be defined as part of a struct ADTs in C++ struct Complex { ; void Complex::init(double r, double i) { im = i; int main () { Complex c1, c2; c1.init(3.0, 2.0); c2.init(4.0,

More information

Chapter 10 Introduction to Classes

Chapter 10 Introduction to Classes C++ for Engineers and Scientists Third Edition Chapter 10 Introduction to Classes CSc 10200! Introduction to Computing Lecture 20-21 Edgardo Molina Fall 2013 City College of New York 2 Objectives In this

More information

Name: Username: I. 20. Section: II. p p p III. p p p p Total 100. CMSC 202 Section 06 Fall 2015

Name: Username: I. 20. Section: II. p p p III. p p p p Total 100. CMSC 202 Section 06 Fall 2015 CMSC 202 Section 06 Fall 2015 Computer Science II Midterm Exam I Name: Username: Score Max Section: (check one) 07 - Sushant Athley, Tuesday 11:30am 08 - Aishwarya Bhide, Thursday 11:30am 09 - Phanindra

More information

Functions, Pointers, and the Basics of C++ Classes

Functions, Pointers, and the Basics of C++ Classes Functions, Pointers, and the Basics of C++ Classes William E. Skeith III Functions in C++ Vocabulary You should be familiar with all of the following terms already, but if not, you will be after today.

More information

Week 8: Operator overloading

Week 8: Operator overloading Due to various disruptions, we did not get through all the material in the slides below. CS319: Scientific Computing (with C++) Week 8: Operator overloading 1 The copy constructor 2 Operator Overloading

More information

+2 Volume II OBJECT TECHNOLOGY OBJECTIVE QUESTIONS R.Sreenivasan SanThome HSS, Chennai-4. Chapter -1

+2 Volume II OBJECT TECHNOLOGY OBJECTIVE QUESTIONS R.Sreenivasan SanThome HSS, Chennai-4. Chapter -1 Chapter -1 1. Object Oriented programming is a way of problem solving by combining data and operation 2.The group of data and operation are termed as object. 3.An object is a group of related function

More information

Reference Parameters A reference parameter is an alias for its corresponding argument in the function call. Use the ampersand (&) to indicate that

Reference Parameters A reference parameter is an alias for its corresponding argument in the function call. Use the ampersand (&) to indicate that Reference Parameters There are two ways to pass arguments to functions: pass-by-value and pass-by-reference. pass-by-value A copy of the argument s value is made and passed to the called function. Changes

More information

CHAPTER 4 FUNCTIONS. 4.1 Introduction

CHAPTER 4 FUNCTIONS. 4.1 Introduction CHAPTER 4 FUNCTIONS 4.1 Introduction Functions are the building blocks of C++ programs. Functions are also the executable segments in a program. The starting point for the execution of a program is main

More information

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe OBJECT ORIENTED PROGRAMMING USING C++ CSCI 5448- Object Oriented Analysis and Design By Manali Torpe Fundamentals of OOP Class Object Encapsulation Abstraction Inheritance Polymorphism Reusability C++

More information

CPSC 427: Object-Oriented Programming

CPSC 427: Object-Oriented Programming CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 21 November 14, 2018 CPSC 427, Lecture 21, November 14, 2018 1/23 Singleton Design Pattern (revisited) More on Functions Casts and Conversions

More information

THE NAME OF THE CONSTRUCTOR AND DESTRUCTOR(HAVING (~) BEFORE ITS NAME) FUNCTION MUST BE SAME AS THE NAME OF THE CLASS IN WHICH THEY ARE DECLARED.

THE NAME OF THE CONSTRUCTOR AND DESTRUCTOR(HAVING (~) BEFORE ITS NAME) FUNCTION MUST BE SAME AS THE NAME OF THE CLASS IN WHICH THEY ARE DECLARED. Constructor and Destructor Member Functions Constructor: - Constructor function gets invoked automatically when an object of a class is constructed (declared). Destructor:- A destructor is a automatically

More information

CS 251 INTERMEDIATE SOFTWARE DESIGN SPRING C ++ Basics Review part 2 Auto pointer, templates, STL algorithms

CS 251 INTERMEDIATE SOFTWARE DESIGN SPRING C ++ Basics Review part 2 Auto pointer, templates, STL algorithms CS 251 INTERMEDIATE SOFTWARE DESIGN SPRING 2011 C ++ Basics Review part 2 Auto pointer, templates, STL algorithms AUTO POINTER (AUTO_PTR) //Example showing a bad situation with naked pointers void MyFunction()

More information

1/29/2011 AUTO POINTER (AUTO_PTR) INTERMEDIATE SOFTWARE DESIGN SPRING delete ptr might not happen memory leak!

1/29/2011 AUTO POINTER (AUTO_PTR) INTERMEDIATE SOFTWARE DESIGN SPRING delete ptr might not happen memory leak! //Example showing a bad situation with naked pointers CS 251 INTERMEDIATE SOFTWARE DESIGN SPRING 2011 C ++ Basics Review part 2 Auto pointer, templates, STL algorithms void MyFunction() MyClass* ptr( new

More information

PIC 10A Objects/Classes

PIC 10A Objects/Classes PIC 10A Objects/Classes Ernest Ryu UCLA Mathematics Last edited: November 13, 2017 User-defined types In C++, we can define our own custom types. Object is synonymous to variable, and class is synonymous

More information

CE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings

CE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings CE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings 19/10/2017 CE221 Part 2 1 Variables and References 1 In Java a variable of primitive type is associated with a memory location

More information

2 ADT Programming User-defined abstract data types

2 ADT Programming User-defined abstract data types Preview 2 ADT Programming User-defined abstract data types user-defined data types in C++: classes constructors and destructors const accessor functions, and inline functions special initialization construct

More information

CS304 Object Oriented Programming Final Term

CS304 Object Oriented Programming Final Term 1. Which of the following is the way to extract common behaviour and attributes from the given classes and make a separate class of those common behaviours and attributes? Generalization (pg 29) Sub-typing

More information

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 12: Classes and Data Abstraction

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 12: Classes and Data Abstraction C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 12: Classes and Data Abstraction Objectives In this chapter, you will: Learn about classes Learn about private, protected,

More information

Abstraction in Software Development

Abstraction in Software Development Abstract Data Types Programmer-created data types that specify values that can be stored (type of data) operations that can be done on the values The user of an abstract data type (ADT) does not need to

More information

Object-Oriented Programming

Object-Oriented Programming - oriented - iuliana@cs.ubbcluj.ro Babes-Bolyai University 2018 1 / 56 Overview - oriented 1 2 -oriented 3 4 5 6 7 8 Static and friend elements 9 Summary 2 / 56 I - oriented was initially created by Bjarne

More information

CMSC 202 Section 010x Spring Justin Martineau, Tuesday 11:30am

CMSC 202 Section 010x Spring Justin Martineau, Tuesday 11:30am CMSC 202 Section 010x Spring 2007 Computer Science II Final Exam Name: Username: Score Max Section: (check one) 0101 - Justin Martineau, Tuesday 11:30am 0102 - Sandeep Balijepalli, Thursday 11:30am 0103

More information

Protection Levels and Constructors The 'const' Keyword

Protection Levels and Constructors The 'const' Keyword Protection Levels and Constructors The 'const' Keyword Review: const Keyword Generally, the keyword const is applied to an identifier (variable) by a programmer to express an intent that the identifier

More information

CSC 210, Exam Two Section February 1999

CSC 210, Exam Two Section February 1999 Problem Possible Score 1 12 2 16 3 18 4 14 5 20 6 20 Total 100 CSC 210, Exam Two Section 004 7 February 1999 Name Unity/Eos ID (a) The exam contains 5 pages and 6 problems. Make sure your exam is complete.

More information

COP4530 Data Structures, Algorithms and Generic Programming Recitation 4 Date: September 14/18-, 2008

COP4530 Data Structures, Algorithms and Generic Programming Recitation 4 Date: September 14/18-, 2008 COP4530 Data Structures, Algorithms and Generic Programming Recitation 4 Date: September 14/18-, 2008 Lab topic: 1) Take Quiz 4 2) Discussion on Assignment 2 Discussion on Assignment 2. Your task is to

More information

Vectors of Pointers to Objects. Vectors of Objects. Vectors of unique ptrs C++11. Arrays of Objects

Vectors of Pointers to Objects. Vectors of Objects. Vectors of unique ptrs C++11. Arrays of Objects Vectors of Objects As we have mentioned earlier, you should almost always use vectors instead of arrays. If you need to keep track of persons (objects of class Person), you must decide what to store in

More information

OBJECT-ORIENTED PROGRAMMING CONCEPTS-CLASSES IV

OBJECT-ORIENTED PROGRAMMING CONCEPTS-CLASSES IV KOM3191 Object Oriented Programming Dr Muharrem Mercimek 1 OBJECT-ORIENTED PROGRAMMING CONCEPTS-CLASSES IV KOM3191 Object-Oriented Programming KOM3191 Object Oriented Programming Dr Muharrem Mercimek 2

More information

Lecture 7. Log into Linux New documents posted to course webpage

Lecture 7. Log into Linux New documents posted to course webpage Lecture 7 Log into Linux New documents posted to course webpage Coding style guideline; part of project grade is following this Homework 4, due on Monday; this is a written assignment Project 1, due next

More information

AN OVERVIEW OF C++ 1

AN OVERVIEW OF C++ 1 AN OVERVIEW OF C++ 1 OBJECTIVES Introduction What is object-oriented programming? Two versions of C++ C++ console I/O C++ comments Classes: A first look Some differences between C and C++ Introducing function

More information

Outline. Introduction. Pointer variables. Pointer operators. Calling functions by reference. Using const with pointers. Examples.

Outline. Introduction. Pointer variables. Pointer operators. Calling functions by reference. Using const with pointers. Examples. Outline Introduction. Pointer variables. Pointer operators. Calling functions by reference. Using const with pointers. Examples. 1 Introduction A pointer is a variable that contains a memory address Pointers

More information

CE221 Programming in C++ Part 1 Introduction

CE221 Programming in C++ Part 1 Introduction CE221 Programming in C++ Part 1 Introduction 06/10/2017 CE221 Part 1 1 Module Schedule There are two lectures (Monday 13.00-13.50 and Tuesday 11.00-11.50) each week in the autumn term, and a 2-hour lab

More information

Intro to OOP Visibility/protection levels and constructors Friend, convert constructor, destructor Operator overloading a<=b a.

Intro to OOP Visibility/protection levels and constructors Friend, convert constructor, destructor Operator overloading a<=b a. Intro to OOP - Object and class - The sequence to define and use a class in a program - How/when to use scope resolution operator - How/when to the dot operator - Should be able to write the prototype

More information

Java Primer 1: Types, Classes and Operators

Java Primer 1: Types, Classes and Operators Java Primer 1 3/18/14 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Java Primer 1: Types,

More information

Motivation was to facilitate development of systems software, especially OS development.

Motivation was to facilitate development of systems software, especially OS development. A History Lesson C Basics 1 Development of language by Dennis Ritchie at Bell Labs culminated in the C language in 1972. Motivation was to facilitate development of systems software, especially OS development.

More information

Tokens, Expressions and Control Structures

Tokens, Expressions and Control Structures 3 Tokens, Expressions and Control Structures Tokens Keywords Identifiers Data types User-defined types Derived types Symbolic constants Declaration of variables Initialization Reference variables Type

More information

Structuur van Computerprogramma s 2

Structuur van Computerprogramma s 2 Structuur van Computerprogramma s 2 dr. Dirk Deridder Dirk.Deridder@vub.ac.be http://soft.vub.ac.be/ Vrije Universiteit Brussel - Faculty of Science and Bio-Engineering Sciences - Computer Science Department

More information

Course "Data Processing" Name: Master-1: Nuclear Energy Session /2018 Examen - Part A Page 1

Course Data Processing Name: Master-1: Nuclear Energy Session /2018 Examen - Part A Page 1 Examen - Part A Page 1 1. mydir directory contains three files: filea.txt fileb.txt filec.txt. How many files will be in the directory after performing the following operations: $ ls filea.txt fileb.txt

More information

These new operators are intended to remove some of the holes in the C type system introduced by the old C-style casts.

These new operators are intended to remove some of the holes in the C type system introduced by the old C-style casts. asting in C++: Bringing Safety and Smartness to Your Programs of 10 10/5/2009 1:20 PM By G. Bowden Wise The new C++ standard is full of powerful additions to the language: templates, run-time type identification

More information

Scope. Scope is such an important thing that we ll review what we know about scope now:

Scope. Scope is such an important thing that we ll review what we know about scope now: Scope Scope is such an important thing that we ll review what we know about scope now: Local (block) scope: A name declared within a block is accessible only within that block and blocks enclosed by it,

More information

Function Declarations. Reference and Pointer Pitfalls. Overloaded Functions. Default Arguments

Function Declarations. Reference and Pointer Pitfalls. Overloaded Functions. Default Arguments Reference and Pointer Pitfalls Function Declarations Never return a reference or a pointer to a local object. The return value will refer to memory that has been deallocated and will be reused on the next

More information

Department of Computer science and Engineering Sub. Name: Object oriented programming and data structures Sub. Code: EC6301 Sem/Class: III/II-ECE Staff name: M.Kavipriya Two Mark Questions UNIT-1 1. List

More information

Cpt S 122 Data Structures. Course Review Midterm Exam # 2

Cpt S 122 Data Structures. Course Review Midterm Exam # 2 Cpt S 122 Data Structures Course Review Midterm Exam # 2 Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Midterm Exam 2 When: Monday (11/05) 12:10 pm -1pm

More information

QUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below:

QUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below: QUIZ 1. Explain the meaning of the angle brackets in the declaration of v below: This is a template, used for generic programming! QUIZ 2. Why is the vector class called a container? 3. Explain how the

More information

C Pointers. 7.2 Pointer Variable Definitions and Initialization

C Pointers. 7.2 Pointer Variable Definitions and Initialization 1 7 C Pointers 7.2 Pointer Variable Definitions and Initialization Pointer variables Contain memory addresses as their values Normal variables contain a specific value (direct reference) Pointers contain

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

Absolute C++ Walter Savitch

Absolute C++ Walter Savitch Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents

More information

SFU CMPT Topic: Class Templates

SFU CMPT Topic: Class Templates SFU CMPT-212 2008-1 1 Topic: Class Templates SFU CMPT-212 2008-1 Topic: Class Templates Ján Maňuch E-mail: jmanuch@sfu.ca Monday 3 rd March, 2008 SFU CMPT-212 2008-1 2 Topic: Class Templates Class templates

More information

Financial computing with C++

Financial computing with C++ Financial Computing with C++, Lecture 11 - p1/24 Financial computing with C++ LG Gyurkó University of Oxford Michaelmas Term 2015 Financial Computing with C++, Lecture 11 - p2/24 Outline Derived classes

More information

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012 MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012 Instructor: K. S. Booth Time: 70 minutes (one hour ten minutes)

More information

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Weiss Chapter 1 terminology (parenthesized numbers are page numbers) Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement

More information

C++ PROGRAMMING LANGUAGE: CLASSES. CAAM 519, CHAPTER 13

C++ PROGRAMMING LANGUAGE: CLASSES. CAAM 519, CHAPTER 13 C++ PROGRAMMING LANGUAGE: CLASSES. CAAM 519, CHAPTER 13 This chapter focuses on introducing the notion of classes in the C++ programming language. We describe how to create class and use an object of a

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

Jayaram college of Engineering and Technology, Pagalavadi. CS2203 Object Oriented Programming Question Bank Prepared By: S.Gopalakrishnan, Lecturer/IT

Jayaram college of Engineering and Technology, Pagalavadi. CS2203 Object Oriented Programming Question Bank Prepared By: S.Gopalakrishnan, Lecturer/IT CS2203 Object Oriented Programming Question Bank Prepared By: S.Gopalakrishnan, Lecturer/IT Two Mark Questions UNIT - I 1. DEFINE ENCAPSULATION. Encapsulation is the process of combining data and functions

More information

CSCI-1200 Data Structures Spring 2018 Lecture 8 Templated Classes & Vector Implementation

CSCI-1200 Data Structures Spring 2018 Lecture 8 Templated Classes & Vector Implementation CSCI-1200 Data Structures Spring 2018 Lecture 8 Templated Classes & Vector Implementation Review from Lectures 7 Algorithm Analysis, Formal Definition of Order Notation Simple recursion, Visualization

More information

Introduction to C++ Introduction to C++ 1

Introduction to C++ Introduction to C++ 1 1 What Is C++? (Mostly) an extension of C to include: Classes Templates Inheritance and Multiple Inheritance Function and Operator Overloading New (and better) Standard Library References and Reference

More information

IS 0020 Program Design and Software Tools

IS 0020 Program Design and Software Tools 1 Introduction 2 IS 0020 Program Design and Software Tools Exception Handling Lecture 12 November 23, 200 Exceptions Indicates problem occurred in program Not common An "exception" to a program that usually

More information

Fundamental Concepts and Definitions

Fundamental Concepts and Definitions Fundamental Concepts and Definitions Identifier / Symbol / Name These terms are synonymous: they refer to the name given to a programming component. Classes, variables, functions, and methods are the most

More information

Outline. 1 Function calls and parameter passing. 2 Pointers, arrays, and references. 5 Declarations, scope, and lifetimes 6 I/O

Outline. 1 Function calls and parameter passing. 2 Pointers, arrays, and references. 5 Declarations, scope, and lifetimes 6 I/O Outline EDAF30 Programming in C++ 2. Introduction. More on function calls and types. Sven Gestegård Robertz Computer Science, LTH 2018 1 Function calls and parameter passing 2 Pointers, arrays, and references

More information

Lecture 5. Function Pointers

Lecture 5. Function Pointers Lecture 5 Pointers to functions Complicated declarations Allocating and deallocating memory Classes const member functions Constructors and destructor this pointer static members Templates Lec 5 Programming

More information

CPSC 427: Object-Oriented Programming

CPSC 427: Object-Oriented Programming CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 7 September 21, 2016 CPSC 427, Lecture 7 1/21 Brackets Example (continued) Storage Management CPSC 427, Lecture 7 2/21 Brackets Example

More information

PHY4321 Summary Notes

PHY4321 Summary Notes PHY4321 Summary Notes The next few pages contain some helpful notes that summarize some of the more useful material from the lecture notes. Be aware, though, that this is not a complete set and doesn t

More information

Chapter 10 Pointers and Dynamic Arrays. GEDB030 Computer Programming for Engineers Fall 2017 Euiseong Seo

Chapter 10 Pointers and Dynamic Arrays. GEDB030 Computer Programming for Engineers Fall 2017 Euiseong Seo Chapter 10 Pointers and Dynamic Arrays 1 Learning Objectives Pointers Pointer variables Memory management Dynamic Arrays Creating and using Pointer arithmetic Classes, Pointers, Dynamic Arrays The this

More information

Constructor - example

Constructor - example Constructors A constructor is a special member function whose task is to initialize the objects of its class. It is special because its name is same as the class name. The constructor is invoked whenever

More information

POLYMORPHISM 2 PART. Shared Interface. Discussions. Abstract Base Classes. Abstract Base Classes and Pure Virtual Methods EXAMPLE

POLYMORPHISM 2 PART. Shared Interface. Discussions. Abstract Base Classes. Abstract Base Classes and Pure Virtual Methods EXAMPLE Abstract Base Classes POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors class B { // base class virtual void m( ) =0; // pure virtual function class D1 : public

More information

POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors

POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors CSC 330 OO Software Design 1 Abstract Base Classes class B { // base class virtual void m( ) =0; // pure virtual

More information

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE?

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE? 1. Describe History of C++? The C++ programming language has a history going back to 1979, when Bjarne Stroustrup was doing work for his Ph.D. thesis. One of the languages Stroustrup had the opportunity

More information

Lecture Topics. Administrivia

Lecture Topics. Administrivia ECE498SL Lec. Notes L8PA Lecture Topics overloading pitfalls of overloading & conversions matching an overloaded call miscellany new & delete variable declarations extensibility: philosophy vs. reality

More information

Computer Programming with C++ (21)

Computer Programming with C++ (21) Computer Programming with C++ (21) Zhang, Xinyu Department of Computer Science and Engineering, Ewha Womans University, Seoul, Korea zhangxy@ewha.ac.kr Classes (III) Chapter 9.7 Chapter 10 Outline Destructors

More information

Preview 9/20/2017. Object Oriented Programing with C++ Object Oriented Programing with C++ Object Oriented Programing with C++

Preview 9/20/2017. Object Oriented Programing with C++ Object Oriented Programing with C++ Object Oriented Programing with C++ Preview Object Oriented Programming with C++ Class Members Inline Functions vs. Regular Functions Constructors & Destructors Initializing class Objects with Constructors C++ Programming Language C Programming

More information

Introduction to Classes

Introduction to Classes Introduction to Classes Procedural and Object-Oriented Programming Procedural and Object-Oriented Programming Procedural programming focuses on the process/actions that occur in a program Object-Oriented

More information

C Pointers. Indirection Indirection = referencing a value through a pointer. Creating Pointers. Pointer Declarations. Pointer Declarations

C Pointers. Indirection Indirection = referencing a value through a pointer. Creating Pointers. Pointer Declarations. Pointer Declarations 55:017, Computers in Engineering C Pointers C Pointers Powerful C feature but challenging to understand Some uses of pointers include Call by reference parameter passage Dynamic data structures Data structures

More information