TDDB89 Advanced Programming in C++ Exercise Smart pointers

Size: px
Start display at page:

Download "TDDB89 Advanced Programming in C++ Exercise Smart pointers"

Transcription

1 TDDB89 Advanced Programming in C++ Exercise Smart pointers In this exercise you shall, given a simple class definition for a smart pointer type, first implement the given member functions and then successively develop the class so the use of such smart pointer s as much as possible resembles the use of ordinary raw pointers, but with certain improved features and implementing some common semantic model for smart pointers. The exercise will comprise a number of interesting constructs in C++ and their use, e.g. templates, member templates, constructors, destructors, implicit type conversion and later on maybe also policy arguments. Smart pointers A smart pointer type shall, basically, have the same features as an ordinary pointer type initialization, copying, assignment, dereferencing (with *) and indirection (using ->). In certain aspects we want a smart pointer to have other and/or better characteristics, e.g. that a smart pointer always is initialized and the memory for the referred object is always deallocated automatically. Other important aspects concerns copying and assignment and these may be implemented according to different models. Typing, to be able to use constant and non-constant smart pointers of a certain type in the same way as ordinary pointers are other aspects. There is a number of implementation models and optimizing techniques for smart pointers. The most known are deep copy (copy-on-create/assign), destructive copy, reference counting, reference linking and copy on write (COW). One specific question concerning copying is if, and in such case how, copying can be performed for smart pointers to polymorphic objects. A base class pointer can point to an object of a derived class and the question is then if it is possible to make a correct copy. Another question is, if it should be possible to initialize a smart pointer to a null pointer, i.e., should there be a default constructor doing this, or should it be allowed to explicitly initialize with a null pointer constant, 0. The C++ standard library includes a smart pointer type, auto_ptr. It is implemented for destructive copy, which means that when an auto_ptr is copied to another auto_ptr, the former will be destroyed. This actually means that the raw pointer is transferred to the copy and the raw pointer in the copied auto_ptr is set to null. Example: auto_ptr<int> sp1(new int(1)); auto_ptr<int> sp2(sp1); sp1 = sp2; // sp1 is initialized with a pointer to an int object. // sp2 takes over, sp1 becomes a null pointer. // sp1 takes over, sp2 becomes a null pointer. The same kind of over-taking takes place, e.g., when a function having a value parameter of type auto_ptr is called. 1

2 Introduction to this exercise Start out from the template class smart_pointer below: template<typename T> class smart_pointer { public: explicit smart_pointer(t* p = 0); smart_pointer(const smart_pointer& rhs); ~smart_pointer(); smart_pointer& operator=(const smart_pointer& rhs); T& operator*() const; T* operator->() const; private: T* ptr; void copy(const smart_pointer<t>& p); }; The template parameter T is the type of object that the smart pointer is to refer to. In smart_pointer, public member functions for initialization, copy, copy assignment and destruction, and also the two basic pointer operations for dereferencing (*) and indirection (->), are declared. The raw pointer and a helper function copy() is declared private. The helper function shall implement the copy semantics used in initialization, copying and assignment. Other member functions performing operations concerning ownership of referred objects shall use copy(). Below are examples of declarations and expressions which shall or shall not be allowed. For comparisons, e.g., there are a number of symmetric cases, but only some examples are given. smart_pointer<x> sp1(new X); // Initialization with a raw pointer. smart_pointer<x> sp2(sp1); // Copy constructor. sp1 = sp2; // Copy assignment. (*sp1).m // Operator *(m is supposed to be a member of X). sp1->m // Operator ->. X* p = new X: smart_pointer<x> sp(p); delete p; delete sp; if (sp) if (!sp) if (sp == 0) if (0 == sp) if (sp!= 0) if (0!= sp) if (sp1 == sp2) if (sp1!= sp2) smart_pointer<x> sp; X* p = new X; if (sp == p) if (sp!= p) // Problem the destructor for sp shall to this to! // Shall not be allowed. // Direct null pointer test. // Negated direct null pointer test. // Explicit test if sp is a null pointer. // Symmetric case. // Explicit test if sp is not a null pointer. // Symmetric case. // Comparison if two smart pointers are equal. // Comparison if two smart pointers are not equal. // Comparing with raw pointer for equality. // Comparing with raw pointer for inequality 2

3 smart_pointer<base> spb; Derived* pd; if (spb == pd) if (spb!= pd) smart_pointer<a> spa; smart_pointer<b> spb; B* p; if (spa == spb) if (spa == p) // Derived is a subclass to Base. // Shall work. // Shall work if it is a meningful comparison, i.e. if // comparing the corresponding raw pointers is meningful. The purpose of the exercises is to implement as many as possible of the desired features for the smart pointer, and at the same time avoid enabling undesired features (e.g. to apply delete on a smart pointer). There can also be features which maybe are desired, e.g. to compare two smart pointers concerning order, i.e. with operator < or a corresponding function object. if (sp1 < sp2) Given code etc. In directory /home/tddb89/kursbibliotek/exercise/smart_pointer/ you find this: The given class definition for smart_pointer is found on the file smart_pointer.h. A test program is found on the file smart_pointer-test.cc. You can use this when developing the smart pointer type, and add more test cases as needed. Some class and function definitions to support testing is found on the file testutils.icc (to be included). Amongst other things, traces showing object initialization and destruction will be printed using these classes and functions. A test program to find out the const semantics for simple objects and raw pointers is found on the file simple-const-test.cc. Two make files for compiling for different test categories, Makefile is uses the GNU GCC C++ compiler, g++, and Makefile.CC uses the Sun C++ compiler, CC. The following targets are declared: make daw make uanw make todo make clean make zap Compile desired constructs ( desired and working ). Compile undesired constructs ( undesired and not working ). Errors shall occur for all Compile desired but not yet working constructs, or undesired but working constructs. Remove certain compilation products. Sun CC: clean the template database (SunWS_cache). Everything, except source code and make files are removed. 3

4 1. Given member functions. Implement the member functions in the given class smart_pointer for copy on create/assign. It is recommended that you start with copy(), which is to implement the copy semantics. Then use copy in the implementation of the other member functions where copying is to be performed. The helper function copy shall make a copy of the object that the parametern p refers to and assign the pointer to that copy to prt in the current smart_pointer object. The function shall return nothing. The parameter p can be a null pointer. The constructor taking a raw pointer of type T* shall initialize the smart pointer object with the raw pointer. Default argument shall be 0, according to the given specification. The copy constructor shall be implemented for copy on create/assign. The destructor shall deallocate the memory for the referred object, if there is such. The copy assignment operator shall perform assignment, according to the semantics for copy on create/assign. operator*() shall return a reference to the referred object. operator->() shall return the pointer ptr. Test the implemented member functions to verify their basic functionality, and also how much of the desired semantics that is achieved by this first implementation, and also if there are any undesired effects. Move all correctly working test cased from to do to desired and working. You can also move all undesired test cases which does not compile to undesired and not working. The operator delete, e.g, shall not be applicable to smart pointers, now or later. Which of the member functions in smart_pointer can be declared to not throw any exceptions, i.e. with an empty exception specification, throws()? 4

5 2. Basic null pointer tests and equality tests. A simple way to allow certain null pointer test and equality test (== and!=) would be to define implicit type conversion from smart_pointer till some other type. The following type conversion operators may be considered: operator T*() operator void*() operator const void*() operator bool() However, implicit type conversion often creates more problems than it solves. Type conversion may occur in situations where it is not at all desired, e.g. making it possible to apply delete to a smart pointer, or allow incompatible smart pointer to be mixed in expressions, or making it possible to use a smart pointer as it if were of arithmetic type. Such possibilities would break the semantics for smart pointers and making it possible to write nonsense code. If one defines operator T*() for allowing implicit type conversion to a raw pointer type, one can also define operator void*() to eliminate the possibility to use delete on smart pointers. delete expressions will then be ambiguous, since it is not possible to choose one of these conversions as better than the other. But, this will only solve some problems and also looks a bit awkward. If one overloads operator! to return true if the smart pointer is a null pointer, otherwise false, some null pointer test will be possible, e.g: if (!sp) if (!!sp) // A somewhat awkward way of testing if (sp) A test which is not possible with simple means (without using implicit type conversion) is direct null pointer test: if (sp) There is an advanced trick for solving this, without allowing for delete, but we postpone this until later. A good solution is to overload the operators!, == and!=. This will take some coding but it can be regarded as reasonable, since we will achieve much of what is desired, without undesired side effects. implement, without using overloaded template versions, the following operators: operator!, to return true if a smart pointer is a null pointer, otherwise false. operator== and operator!= to compare, with respect to equality and inequality, two smart pointer of the same type, or one smart pointer and one corresponding raw pointer of corresponding type, or one smart pointer and a null pointer constant. Test the operators. Move working test cases from to do to desired and working. 5

6 3. More null pointer test and equality tests. Now you are going to make it possible to compare smart pointers with respect to equality (==) and inequality (!=) also for the following cases: Comparing two smart pointers instantiated for different but compatible types, T and U. If a comparison between the raw pointer types T* and U* is accepted, i.e. compiles, a comparison between the corresponding smart pointers shall also be accepted. Comparing one smart pointer instantiated for a certain type T with a raw pointer of type U*, where U is a different type than T. If a comparison between the raw pointer types T* and U* is accepted, i.e. compiles, a comparison between the smart pointer and the raw pointer shall also be accepted. Smart pointers shall consequently, in these respects, follow the same rules as the corresponding raw pointers. implement, test and move working test cases to desired and working. 6

7 4. Smart pointers and const. For raw pointers we have the following possibilities to use const qualifiers: int* p; // pointer to int const int* pc; // pointer to constant int int* const cp = new int(1); // constant pointer to int const int* const cpc = new int(2); // constant pointer to constant int The corresponding smart pointers are: smart_pointer<int> sp; smart_pointer<const int> spc; const smart_pointer<int> csp(new int(3)); const smart_pointer<const int> cspc(new int(4)); It is desired that smart pointers follow the same rules as for raw pointer, concerning const. E.g., a const smart pointer must be initialized and may not be altered thereafter, a smart pointer to const may point to either a const or a non-const object, etc. Check how much of const semantics that is already supported by implementation so far. Move the desired and working test cases to desired and working, and the undesired and not working test cases to undesired and not working. Try to implement any desired but not yet working test cases. Remember, e.g., that smart_pointer<int> and smart_pointer<const int> are completely different types and unrelated, as far as the compiler knows, so you have to find a way to make it possible to initialize or assign a smart_pointer<const int> with a smart_pointer<int>. Note: For some aid to find out the rules for raw pointers, see simple-const-tests.cc. 7

8 5. Direct null pointer test. Now it s time for implementing direct null pointer test, without allowing for undesired features. We want to be able to write code like this: if (sp1) // false if sp1 is a null smart pointer, true otherwise As said above, this can be made possible by defining implicit type conversion from smart_pointer<t> to the corresponding raw pointer type T*, or to void*, const void* or bool. Unfortunately such conversions may also allow for applying delete to a smart pointer, or to use the smart pointer as if it was an arithmetic type. To be able to name a smart pointer object where an expression of type bool is expected, implicit type conversion must be used. The question is what to convert to, to allow for direct null pointer test but no more? Hint: The solution is a trick of advanced kind. It is basically fairly natural, in the sense that it shall be a conversion to a pointer type. The trick is more related to the declaration of the referred type. This type is really not of interest for the user, and therefore we want to minimize its visibility, which can be done quite well by taking advantage of a maybe not obvious feature of the C++ language. Also, the possibility to operate on the type should be minimized, since a pointer to such an object is returned to the user by the type conversion operator. The only thing we want to allow is testing whether the returned pointer is a null pointer, or not. After this step, most or all of the desired operations for smart_pointer should be achieved, and, hopefully, no undesired features have emerged. 8

Object Oriented Software Design II

Object Oriented Software Design II Object Oriented Software Design II Introduction to C++ Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 20, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February

More information

C++ Overloading, Constructors, Assignment operator

C++ Overloading, Constructors, Assignment operator C++ Overloading, Constructors, Assignment operator 1 Overloading Before looking at the initialization of objects in C++ with constructors, we need to understand what function overloading is In C, two functions

More information

C++ INTERVIEW QUESTIONS

C++ INTERVIEW QUESTIONS C++ INTERVIEW QUESTIONS http://www.tutorialspoint.com/cplusplus/cpp_interview_questions.htm Copyright tutorialspoint.com Dear readers, these C++ Interview Questions have been designed specially to get

More information

The C Programming Language course syllabus associate level

The C Programming Language course syllabus associate level TECHNOLOGIES The C Programming Language course syllabus associate level Course description The course fully covers the basics of programming in the C programming language and demonstrates fundamental programming

More information

1 bool operator==(complex a, Complex b) { 2 return a.real()==b.real() 3 && a.imag()==b.imag(); 4 } 1 bool Complex::operator==(Complex b) {

1 bool operator==(complex a, Complex b) { 2 return a.real()==b.real() 3 && a.imag()==b.imag(); 4 } 1 bool Complex::operator==(Complex b) { Operators C and C++ 6. Operators Inheritance Virtual Alastair R. Beresford University of Cambridge Lent Term 2008 C++ allows the programmer to overload the built-in operators For example, a new test for

More information

Java Interview Questions and Answers

Java Interview Questions and Answers 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java

More information

Data Structures Using C++ 2E. Chapter 5 Linked Lists

Data Structures Using C++ 2E. Chapter 5 Linked Lists Data Structures Using C++ 2E Chapter 5 Linked Lists Test #1 Next Thursday During Class Cover through (near?) end of Chapter 5 Objectives Learn about linked lists Become aware of the basic properties of

More information

CS193D Handout 06 Winter 2004 January 26, 2004 Copy Constructor and operator=

CS193D Handout 06 Winter 2004 January 26, 2004 Copy Constructor and operator= CS193D Handout 06 Winter 2004 January 26, 2004 Copy Constructor and operator= We already know that the compiler will supply a default (zero-argument) constructor if the programmer does not specify one.

More information

Compile-time type versus run-time type. Consider the parameter to this function:

Compile-time type versus run-time type. Consider the parameter to this function: CS107L Handout 07 Autumn 2007 November 16, 2007 Advanced Inheritance and Virtual Methods Employee.h class Employee public: Employee(const string& name, double attitude, double wage); virtual ~Employee();

More information

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas CS 110B - Rule Storage Classes Page 18-1 Attributes are distinctive features of a variable. Data type, int or double for example, is an attribute. Storage class is another attribute. There are four storage

More information

The Universal Reference/Overloading Collision Conundruim

The Universal Reference/Overloading Collision Conundruim The materials shown here differ from those I used in my presentation at the Northwest C++ Users Group. Compared to the materials I presented, these materials correct a variety of technical errors whose

More information

IS0020 Program Design and Software Tools Midterm, Feb 24, 2004. Instruction

IS0020 Program Design and Software Tools Midterm, Feb 24, 2004. Instruction IS0020 Program Design and Software Tools Midterm, Feb 24, 2004 Name: Instruction There are two parts in this test. The first part contains 50 questions worth 80 points. The second part constitutes 20 points

More information

N3458: Simple Database Integration in C++11

N3458: Simple Database Integration in C++11 N3458: Simple Database Integration in C++11 Thomas Neumann Technische Univeristät München neumann@in.tum.de 2012-10-22 Many applications make use of relational database to store and query their data. However,

More information

Web development... the server side (of the force)

Web development... the server side (of the force) Web development... the server side (of the force) Fabien POULARD Document under license Creative Commons Attribution Share Alike 2.5 http://www.creativecommons.org/learnmore Web development... the server

More information

Splicing Maps and Sets

Splicing Maps and Sets Document number: N3586 Date: 2013-03-17 Project: Programming Language C++ Reference: N3485 Reply to: Alan Talbot cpp@alantalbot.com Howard Hinnant howard.hinnant@gmail.com Related Documents Splicing Maps

More information

CS11 Advanced C++ Spring 2008-2009 Lecture 9 (!!!)

CS11 Advanced C++ Spring 2008-2009 Lecture 9 (!!!) CS11 Advanced C++ Spring 2008-2009 Lecture 9 (!!!) The static Keyword C++ provides the static keyword Also in C, with slightly different usage Used in two main contexts: Declaring static members of a class

More information

Operator Overloading. Lecture 8. Operator Overloading. Running Example: Complex Numbers. Syntax. What can be overloaded. Syntax -- First Example

Operator Overloading. Lecture 8. Operator Overloading. Running Example: Complex Numbers. Syntax. What can be overloaded. Syntax -- First Example Operator Overloading Lecture 8 Operator Overloading C++ feature that allows implementer-defined classes to specify class-specific function for operators Benefits allows classes to provide natural semantics

More information

CISC 181 Project 3 Designing Classes for Bank Accounts

CISC 181 Project 3 Designing Classes for Bank Accounts CISC 181 Project 3 Designing Classes for Bank Accounts Code Due: On or before 12 Midnight, Monday, Dec 8; hardcopy due at beginning of lecture, Tues, Dec 9 What You Need to Know This project is based on

More information

Applied Informatics C++ Coding Style Guide

Applied Informatics C++ Coding Style Guide C++ Coding Style Guide Rules and Recommendations Version 1.4 Purpose of This Document This document describes the C++ coding style employed by Applied Informatics. The document is targeted at developers

More information

Variable Base Interface

Variable Base Interface Chapter 6 Variable Base Interface 6.1 Introduction Finite element codes has been changed a lot during the evolution of the Finite Element Method, In its early times, finite element applications were developed

More information

6.088 Intro to C/C++ Day 4: Object-oriented programming in C++ Eunsuk Kang and Jean Yang

6.088 Intro to C/C++ Day 4: Object-oriented programming in C++ Eunsuk Kang and Jean Yang 6.088 Intro to C/C++ Day 4: Object-oriented programming in C++ Eunsuk Kang and Jean Yang Today s topics Why objects? Object-oriented programming (OOP) in C++ classes fields & methods objects representation

More information

Object Oriented Software Design II

Object Oriented Software Design II Object Oriented Software Design II C++ intro Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 26, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 26,

More information

Binary compatibility for library developers. Thiago Macieira, Qt Core Maintainer LinuxCon North America, New Orleans, Sept. 2013

Binary compatibility for library developers. Thiago Macieira, Qt Core Maintainer LinuxCon North America, New Orleans, Sept. 2013 Binary compatibility for library developers Thiago Macieira, Qt Core Maintainer LinuxCon North America, New Orleans, Sept. 2013 Who am I? Open Source developer for 15 years C++ developer for 13 years Software

More information

C++ Crash Kurs. C++ Object-Oriented Programming

C++ Crash Kurs. C++ Object-Oriented Programming C++ Crash Kurs C++ Object-Oriented Programming Dr. Dennis Pfisterer Institut für Telematik, Universität zu Lübeck http://www.itm.uni-luebeck.de/people/pfisterer C++ classes A class is user-defined type

More information

C++FA 3.1 OPTIMIZING C++

C++FA 3.1 OPTIMIZING C++ C++FA 3.1 OPTIMIZING C++ Ben Van Vliet Measuring Performance Performance can be measured and judged in different ways execution time, memory usage, error count, ease of use and trade offs usually have

More information

El Dorado Union High School District Educational Services

El Dorado Union High School District Educational Services El Dorado Union High School District Course of Study Information Page Course Title: ACE Computer Programming II (#495) Rationale: A continuum of courses, including advanced classes in technology is needed.

More information

Sources: On the Web: Slides will be available on:

Sources: On the Web: Slides will be available on: C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,

More information

CSCI 253. Object Oriented Programming (OOP) Overview. George Blankenship 1. Object Oriented Design: Java Review OOP George Blankenship.

CSCI 253. Object Oriented Programming (OOP) Overview. George Blankenship 1. Object Oriented Design: Java Review OOP George Blankenship. CSCI 253 Object Oriented Design: Java Review OOP George Blankenship George Blankenship 1 Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation Abstract Data Type (ADT) Implementation

More information

vector vec double # in # cl in ude <s ude tdexcept> tdexcept> // std::ou std t_of ::ou _range t_of class class V Vector { ector {

vector vec double # in # cl in ude <s ude tdexcept> tdexcept> // std::ou std t_of ::ou _range t_of class class V Vector { ector { Software Design (C++) 3. Resource management and exception safety (idioms and technicalities) Juha Vihavainen University of Helsinki Preview More on error handling and exceptions checking array indices

More information

Software Engineering Concepts: Testing. Pointers & Dynamic Allocation. CS 311 Data Structures and Algorithms Lecture Slides Monday, September 14, 2009

Software Engineering Concepts: Testing. Pointers & Dynamic Allocation. CS 311 Data Structures and Algorithms Lecture Slides Monday, September 14, 2009 Software Engineering Concepts: Testing Simple Class Example continued Pointers & Dynamic Allocation CS 311 Data Structures and Algorithms Lecture Slides Monday, September 14, 2009 Glenn G. Chappell Department

More information

CS107L Handout 04 Autumn 2007 October 19, 2007 Custom STL-Like Containers and Iterators

CS107L Handout 04 Autumn 2007 October 19, 2007 Custom STL-Like Containers and Iterators CS107L Handout 04 Autumn 2007 October 19, 2007 Custom STL-Like Containers and Iterators This handout is designed to provide a better understanding of how one should write template code and architect iterators

More information

Introduction to C++ Introduction to C++ Week 7 Dr Alex Martin 2013 Slide 1

Introduction to C++ Introduction to C++ Week 7 Dr Alex Martin 2013 Slide 1 Introduction to C++ Introduction to C++ Week 7 Dr Alex Martin 2013 Slide 1 Introduction to Classes Classes as user-defined types We have seen that C++ provides a fairly large set of built-in types. e.g

More information

Coding conventions and C++-style

Coding conventions and C++-style Chapter 1 Coding conventions and C++-style This document provides an overview of the general coding conventions that are used throughout oomph-lib. Knowledge of these conventions will greatly facilitate

More information

CpSc212 Goddard Notes Chapter 6. Yet More on Classes. We discuss the problems of comparing, copying, passing, outputting, and destructing

CpSc212 Goddard Notes Chapter 6. Yet More on Classes. We discuss the problems of comparing, copying, passing, outputting, and destructing CpSc212 Goddard Notes Chapter 6 Yet More on Classes We discuss the problems of comparing, copying, passing, outputting, and destructing objects. 6.1 Object Storage, Allocation and Destructors Some objects

More information

Moving from CS 61A Scheme to CS 61B Java

Moving from CS 61A Scheme to CS 61B Java Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you

More information

CIS 190: C/C++ Programming. Polymorphism

CIS 190: C/C++ Programming. Polymorphism CIS 190: C/C++ Programming Polymorphism Outline Review of Inheritance Polymorphism Car Example Virtual Functions Virtual Function Types Virtual Table Pointers Virtual Constructors/Destructors Review of

More information

Linked List as an ADT (cont d.)

Linked List as an ADT (cont d.) Linked List as an ADT (cont d.) Default constructor Initializes list to an empty state Destroy the list Deallocates memory occupied by each node Initialize the list Reinitializes list to an empty state

More information

Constructor, Destructor, Accessibility and Virtual Functions

Constructor, Destructor, Accessibility and Virtual Functions Constructor, Destructor, Accessibility and Virtual Functions 182.132 VL Objektorientierte Programmierung Raimund Kirner Mitwirkung an Folienerstellung: Astrit Ademaj Agenda Constructor Destructors this

More information

Chapter 5 Names, Bindings, Type Checking, and Scopes

Chapter 5 Names, Bindings, Type Checking, and Scopes Chapter 5 Names, Bindings, Type Checking, and Scopes Chapter 5 Topics Introduction Names Variables The Concept of Binding Type Checking Strong Typing Scope Scope and Lifetime Referencing Environments Named

More information

Conversion Constructors

Conversion Constructors CS106L Winter 2007-2008 Handout #18 Wednesday, February 27 Conversion Constructors Introduction When designing classes, you might find that certain data types can logically be converted into objects of

More information

Glossary of Object Oriented Terms

Glossary of Object Oriented Terms Appendix E Glossary of Object Oriented Terms abstract class: A class primarily intended to define an instance, but can not be instantiated without additional methods. abstract data type: An abstraction

More information

A deeper look at Inline functions

A deeper look at Inline functions A deeper look at Inline functions I think it s safe to say that all Overload readers know what C++ inline functions are. When we declare a function or member function as inline we are trying to avoid the

More information

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement? 1. Distinguish & and && operators. PART-A Questions 2. How does an enumerated statement differ from a typedef statement? 3. What are the various members of a class? 4. Who can access the protected members

More information

public static void main(string[] args) { System.out.println("hello, world"); } }

public static void main(string[] args) { System.out.println(hello, world); } } Java in 21 minutes hello world basic data types classes & objects program structure constructors garbage collection I/O exceptions Strings Hello world import java.io.*; public class hello { public static

More information

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

KITES TECHNOLOGY COURSE MODULE (C, C++, DS) KITES TECHNOLOGY 360 Degree Solution www.kitestechnology.com/academy.php info@kitestechnology.com technologykites@gmail.com Contact: - 8961334776 9433759247 9830639522.NET JAVA WEB DESIGN PHP SQL, PL/SQL

More information

13 Classes & Objects with Constructors/Destructors

13 Classes & Objects with Constructors/Destructors 13 Classes & Objects with Constructors/Destructors 13.1 Introduction In object oriented programming, the emphasis is on data rather than function. Class is a way that binds the data & function together.

More information

Course Name: ADVANCE COURSE IN SOFTWARE DEVELOPMENT (Specialization:.Net Technologies)

Course Name: ADVANCE COURSE IN SOFTWARE DEVELOPMENT (Specialization:.Net Technologies) Course Name: ADVANCE COURSE IN SOFTWARE DEVELOPMENT (Specialization:.Net Technologies) Duration of Course: 6 Months Fees: Rs. 25,000/- (including Service Tax) Eligibility: B.E./B.Tech., M.Sc.(IT/ computer

More information

MSP430 C/C++ CODE GENERATION TOOLS Compiler Version 3.2.X Parser Error/Warning/Remark List

MSP430 C/C++ CODE GENERATION TOOLS Compiler Version 3.2.X Parser Error/Warning/Remark List MSP430 C/C++ CODE GENERATION TOOLS Compiler Version 3.2.X Parser Error/Warning/Remark List This is a list of the error/warning messages generated by the Texas Instruments C/C++ parser (which we license

More information

OpenCL Static C++ Kernel Language Extension

OpenCL Static C++ Kernel Language Extension OpenCL Static C++ Kernel Language Extension Document Revision: 04 Advanced Micro Devices Authors: Ofer Rosenberg, Benedict R. Gaster, Bixia Zheng, Irina Lipov December 15, 2011 Contents 1 Overview... 3

More information

Polymorphism. Problems with switch statement. Solution - use virtual functions (polymorphism) Polymorphism

Polymorphism. Problems with switch statement. Solution - use virtual functions (polymorphism) Polymorphism Polymorphism Problems with switch statement Programmer may forget to test all possible cases in a switch. Tracking this down can be time consuming and error prone Solution - use virtual functions (polymorphism)

More information

The Function Pointer

The Function Pointer The Function Pointer 1. Introduction to Function Pointers Function Pointers provide some extremely interesting, efficient and elegant programming techniques. You can use them to replace switch/if-statements,

More information

Object Oriented Programming With C++(10CS36) Question Bank. UNIT 1: Introduction to C++

Object Oriented Programming With C++(10CS36) Question Bank. UNIT 1: Introduction to C++ Question Bank UNIT 1: Introduction to C++ 1. What is Procedure-oriented Programming System? Dec 2005 2. What is Object-oriented Programming System? June 2006 3. Explain the console I/O functions supported

More information

Brent A. Perdue. July 15, 2009

Brent A. Perdue. July 15, 2009 Title Page Object-Oriented Programming, Writing Classes, and Creating Libraries and Applications Brent A. Perdue ROOT @ TUNL July 15, 2009 B. A. Perdue (TUNL) OOP, Classes, Libraries, Applications July

More information

Data Structures Using C++ 2E. Chapter 5 Linked Lists

Data Structures Using C++ 2E. Chapter 5 Linked Lists Data Structures Using C++ 2E Chapter 5 Linked Lists Doubly Linked Lists Traversed in either direction Typical operations Initialize the list Destroy the list Determine if list empty Search list for a given

More information

C++ Programming Language

C++ Programming Language C++ Programming Language Lecturer: Yuri Nefedov 7th and 8th semesters Lectures: 34 hours (7th semester); 32 hours (8th semester). Seminars: 34 hours (7th semester); 32 hours (8th semester). Course abstract

More information

Copyright 2001, Bill Trudell. Permission is granted to copy for the PLoP 2001 conference. All other rights reserved.

Copyright 2001, Bill Trudell. Permission is granted to copy for the PLoP 2001 conference. All other rights reserved. The Secret Partner Pattern Revision 3a by Bill Trudell, July 23, 2001 Submitted to the Pattern Languages of Programs Shepherd: Neil Harrison PC Member: Kyle Brown Thumbnail This paper describes the Secret

More information

CORBA Programming with TAOX11. The C++11 CORBA Implementation

CORBA Programming with TAOX11. The C++11 CORBA Implementation CORBA Programming with TAOX11 The C++11 CORBA Implementation TAOX11: the CORBA Implementation by Remedy IT TAOX11 simplifies development of CORBA based applications IDL to C++11 language mapping is easy

More information

Application Note C++ Debugging

Application Note C++ Debugging Application Note C++ Debugging TRACE32 Online Help TRACE32 Directory TRACE32 Index TRACE32 Documents... High-Level Language Debugging... Application Note C++ Debugging... 1 Sample Code used by This Application

More information

Friendship and Encapsulation in C++

Friendship and Encapsulation in C++ Friendship and Encapsulation in C++ Adrian P Robson Department of Computing University of Northumbria at Newcastle 23rd October 1995 Abstract There is much confusion and debate about friendship and encapsulation

More information

1 Abstract Data Types Information Hiding

1 Abstract Data Types Information Hiding 1 1 Abstract Data Types Information Hiding 1.1 Data Types Data types are an integral part of every programming language. ANSI-C has int, double and char to name just a few. Programmers are rarely content

More information

1.1.3 Syntax The syntax for creating a derived class is very simple. (You will wish everything else about it were so simple though.

1.1.3 Syntax The syntax for creating a derived class is very simple. (You will wish everything else about it were so simple though. Stewart Weiss Inheritance is a feature that is present in many object-oriented languages such as C++, Eiffel, Java, Ruby, and Smalltalk, but each language implements it in its own way. This chapter explains

More information

Introduction to Objective-C. Kevin Cathey

Introduction to Objective-C. Kevin Cathey Introduction to Objective-C Kevin Cathey Introduction to Objective-C What are object-oriented systems? What is the Objective-C language? What are objects? How do you create classes in Objective-C? acm.uiuc.edu/macwarriors/devphone

More information

Binary storage of graphs and related data

Binary storage of graphs and related data EÖTVÖS LORÁND UNIVERSITY Faculty of Informatics Department of Algorithms and their Applications Binary storage of graphs and related data BSc thesis Author: Frantisek Csajka full-time student Informatics

More information

Basic Logic Gates. Logic Gates. andgate: accepts two binary inputs x and y, emits x & y. orgate: accepts two binary inputs x and y, emits x y

Basic Logic Gates. Logic Gates. andgate: accepts two binary inputs x and y, emits x & y. orgate: accepts two binary inputs x and y, emits x y Basic andgate: accepts two binary inputs x and y, emits x & y x y Output orgate: accepts two binary inputs x and y, emits x y x y Output notgate: accepts one binary input x, emits!y x Output Computer Science

More information

Node-Based Structures Linked Lists: Implementation

Node-Based Structures Linked Lists: Implementation Linked Lists: Implementation CS 311 Data Structures and Algorithms Lecture Slides Monday, March 30, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks CHAPPELLG@member.ams.org

More information

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is preceded by an equal sign d. its name has undereline 2. Associations

More information

Basics of C++ and object orientation in OpenFOAM

Basics of C++ and object orientation in OpenFOAM Basics of C++ and object orientation in OpenFOAM To begin with: The aim of this part of the course is not to teach all of C++, but to give a short introduction that is useful when trying to understand

More information

CS 111 Classes I 1. Software Organization View to this point:

CS 111 Classes I 1. Software Organization View to this point: CS 111 Classes I 1 Software Organization View to this point: Data Objects and primitive types Primitive types operators (+, /,,*, %). int, float, double, char, boolean Memory location holds the data Objects

More information

Linked Lists: Implementation Sequences in the C++ STL

Linked Lists: Implementation Sequences in the C++ STL Linked Lists: Implementation Sequences in the C++ STL continued CS 311 Data Structures and Algorithms Lecture Slides Wednesday, April 1, 2009 Glenn G. Chappell Department of Computer Science University

More information

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and: Binary Search Trees 1 The general binary tree shown in the previous chapter is not terribly useful in practice. The chief use of binary trees is for providing rapid access to data (indexing, if you will)

More information

CS107L Handout 02 Autumn 2007 October 5, 2007 Copy Constructor and operator=

CS107L Handout 02 Autumn 2007 October 5, 2007 Copy Constructor and operator= CS107L Handout 02 Autumn 2007 October 5, 2007 Copy Constructor and operator= Much of the surrounding prose written by Andy Maag, CS193D instructor from years ago. The compiler will supply a default (zero-argument)

More information

16 Collection Classes

16 Collection Classes 16 Collection Classes Collections are a key feature of the ROOT system. Many, if not most, of the applications you write will use collections. If you have used parameterized C++ collections or polymorphic

More information

Using the Remote Access Library

Using the Remote Access Library Using the Remote Access Library The Remote Access Library (RACLib) was created to give non-skywire Software applications the ability to start, stop, and control (to some degree) the Documaker Workstation,

More information

C Programming Review & Productivity Tools

C Programming Review & Productivity Tools Review & Productivity Tools Giovanni Agosta Piattaforme Software per la Rete Modulo 2 Outline Preliminaries 1 Preliminaries 2 Function Pointers Variadic Functions 3 Build Automation Code Versioning 4 Preliminaries

More information

For the next three questions, consider the class declaration: Member function implementations put inline to save space.

For the next three questions, consider the class declaration: Member function implementations put inline to save space. Instructions: This homework assignment focuses on basic facts regarding classes in C++. Submit your answers via the Curator System as OQ4. For the next three questions, consider the class declaration:

More information

6.S096 Lecture 1 Introduction to C

6.S096 Lecture 1 Introduction to C 6.S096 Lecture 1 Introduction to C Welcome to the Memory Jungle Andre Kessler Andre Kessler 6.S096 Lecture 1 Introduction to C 1 / 30 Outline 1 Motivation 2 Class Logistics 3 Memory Model 4 Compiling 5

More information

GDB Tutorial. A Walkthrough with Examples. CMSC 212 - Spring 2009. Last modified March 22, 2009. GDB Tutorial

GDB Tutorial. A Walkthrough with Examples. CMSC 212 - Spring 2009. Last modified March 22, 2009. GDB Tutorial A Walkthrough with Examples CMSC 212 - Spring 2009 Last modified March 22, 2009 What is gdb? GNU Debugger A debugger for several languages, including C and C++ It allows you to inspect what the program

More information

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON PROBLEM SOLVING WITH SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON Addison Wesley Boston San Francisco New York London

More information

Habanero Extreme Scale Software Research Project

Habanero Extreme Scale Software Research Project Habanero Extreme Scale Software Research Project Comp215: Java Method Dispatch Zoran Budimlić (Rice University) Always remember that you are absolutely unique. Just like everyone else. - Margaret Mead

More information

Lecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists

Lecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists Lecture 11 Doubly Linked Lists & Array of Linked Lists In this lecture Doubly linked lists Array of Linked Lists Creating an Array of Linked Lists Representing a Sparse Matrix Defining a Node for a Sparse

More information

Description of Class Mutation Mutation Operators for Java

Description of Class Mutation Mutation Operators for Java Description of Class Mutation Mutation Operators for Java Yu-Seung Ma Electronics and Telecommunications Research Institute, Korea ysma@etri.re.kr Jeff Offutt Software Engineering George Mason University

More information

Sequences in the C++ STL

Sequences in the C++ STL CS 311 Data Structures and Algorithms Lecture Slides Wednesday, November 4, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks CHAPPELLG@member.ams.org 2005 2009 Glenn

More information

Delegating Constructors (revision 3)

Delegating Constructors (revision 3) Doc No: SC22/WG21/N1986 J16/06 0056 Date: 2006 04 06 Project: JTC1.22.32 Reply to: Herb Sutter Francis Glassborow Microsoft Corp. Association of C & C++ Users 1 Microsoft Way 64 Southfield Road Redmond

More information

AP Computer Science Java Subset

AP Computer Science Java Subset APPENDIX A AP Computer Science Java Subset The AP Java subset is intended to outline the features of Java that may appear on the AP Computer Science A Exam. The AP Java subset is NOT intended as an overall

More information

Semantic Analysis: Types and Type Checking

Semantic Analysis: Types and Type Checking Semantic Analysis Semantic Analysis: Types and Type Checking CS 471 October 10, 2007 Source code Lexical Analysis tokens Syntactic Analysis AST Semantic Analysis AST Intermediate Code Gen lexical errors

More information

Organization of Programming Languages CS320/520N. Lecture 05. Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.

Organization of Programming Languages CS320/520N. Lecture 05. Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio. Organization of Programming Languages CS320/520N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Names, Bindings, and Scopes A name is a symbolic identifier used

More information

An Internet Course in Software Development with C++ for Engineering Students

An Internet Course in Software Development with C++ for Engineering Students An Internet Course in Software Development with C++ for Engineering Students Yosef Gavriel, Robert Broadwater Department of Electrical and Computer Engineering Virginia Tech Session 3232 Abstract This

More information

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following: In creating objects of the type, we have used statements similar to the following: f = new (); The parentheses in the expression () makes it look like a method, yet we never created such a method in our

More information

1 Description of The Simpletron

1 Description of The Simpletron Simulating The Simpletron Computer 50 points 1 Description of The Simpletron In this assignment you will write a program to simulate a fictional computer that we will call the Simpletron. As its name implies

More information

Grundlagen der Betriebssystemprogrammierung

Grundlagen der Betriebssystemprogrammierung Grundlagen der Betriebssystemprogrammierung Präsentation A3, A4, A5, A6 21. März 2013 IAIK Grundlagen der Betriebssystemprogrammierung 1 / 73 1 A3 - Function Pointers 2 A4 - C++: The good, the bad and

More information

Interpreters and virtual machines. Interpreters. Interpreters. Why interpreters? Tree-based interpreters. Text-based interpreters

Interpreters and virtual machines. Interpreters. Interpreters. Why interpreters? Tree-based interpreters. Text-based interpreters Interpreters and virtual machines Michel Schinz 2007 03 23 Interpreters Interpreters Why interpreters? An interpreter is a program that executes another program, represented as some kind of data-structure.

More information

Image Acquisition Toolbox Adaptor Kit User's Guide

Image Acquisition Toolbox Adaptor Kit User's Guide Image Acquisition Toolbox Adaptor Kit User's Guide R2015b How to Contact MathWorks Latest news: www.mathworks.com Sales and services: www.mathworks.com/sales_and_services User community: www.mathworks.com/matlabcentral

More information

Managing Variability in Software Architectures 1 Felix Bachmann*

Managing Variability in Software Architectures 1 Felix Bachmann* Managing Variability in Software Architectures Felix Bachmann* Carnegie Bosch Institute Carnegie Mellon University Pittsburgh, Pa 523, USA fb@sei.cmu.edu Len Bass Software Engineering Institute Carnegie

More information

Parameter Passing. Standard mechanisms. Call by value-result Call by name, result

Parameter Passing. Standard mechanisms. Call by value-result Call by name, result Parameter Passing Standard mechanisms Call by value Call by reference Other methods Call by value-result Call by name, result Terms Function definition where the details of the function are presented (type,

More information

No no-argument constructor. No default constructor found

No no-argument constructor. No default constructor found Every software developer deals with bugs. The really tough bugs aren t detected by the compiler. Nasty bugs manifest themselves only when executed at runtime. Here is a list of the top ten difficult and

More information

Type Classes with Functional Dependencies

Type Classes with Functional Dependencies Appears in Proceedings of the 9th European Symposium on Programming, ESOP 2000, Berlin, Germany, March 2000, Springer-Verlag LNCS 1782. Type Classes with Functional Dependencies Mark P. Jones Department

More information

VHDL Test Bench Tutorial

VHDL Test Bench Tutorial University of Pennsylvania Department of Electrical and Systems Engineering ESE171 - Digital Design Laboratory VHDL Test Bench Tutorial Purpose The goal of this tutorial is to demonstrate how to automate

More information

Compile Time and Run Time Performance with the Sun C++ Compiler

Compile Time and Run Time Performance with the Sun C++ Compiler Compile Time and Run Time Performance with the Sun C++ Compiler Lawrence Crowl Sun Microsystems Inc. Forte Tools ABSTRACT The organization of your C++ software can have a significant impact on both compile

More information

arrays C Programming Language - Arrays

arrays C Programming Language - Arrays arrays So far, we have been using only scalar variables scalar meaning a variable with a single value But many things require a set of related values coordinates or vectors require 3 (or 2, or 4, or more)

More information

Policy-Based Class Design

Policy-Based Class Design Part I Techniques 1 Policy-Based Class Design This chapter describes policies and policy classes, important class design techniques that enable the creation of flexible, highly reusable libraries as Loki

More information