Class template Describing a generic class Instantiating classes that are type- specific version of this generic class Also are called parameterized types.

Slides:



Advertisements
Similar presentations
Engineering Problem Solving With C++ An Object Based Approach Additional Topics Chapter 10 Programming with Classes.
Advertisements

Template. 2 Using templates, it is possible to create generic functions and classes. In a generic function or class, the type of data upon which the function.
OBJECT ORIENTED FEATURES AND IMPLEMENTATION OF UNIVERSAL QUANTIFICATION IN C++ Karoly Bosa RISC SS2000.
Chapter 17 Templates. Generic Algorithms Algorithms in which the actions or steps are defined, but the data types of the items being manipulated are not.
1 Templates Chapter What You Will Learn Using function templates to created a group of overloaded functions Using class templates to create a group.
Derived Classes. C++ 2 Outline  Definition  Virtual functions  Virtual base classes  Abstract classes. Pure virtual functions.
C++ Classes & Data Abstraction
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 23 : Generics King Fahd University of Petroleum & Minerals College of Computer Science.
Generics and The ArrayList Class
C++ How to Program, 7/e © by Pearson Education, Inc. All Rights Reserved.
Creating Classes from Other Classes Chapter 2 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
1 Composition A whole-part relationship (e.g. Dog-Tail) Whole and part objects have same lifetime –Whole creates instance of part in its constructor In.
Class template Describing a generic class Instantiating classes that are type-specific version of this generic class Also are called parameterized types.
Slides prepared by Rose Williams, Binghamton University Chapter 14 Generics and the ArrayList Class.
C++ data types. Structs vs. Classes C++ Classes.
1 Lab Session-5 CSIT221 Spring 2003 Default and Parameterized Constructors Destructors Programming Exercise for building a template based class (demo required)
Using Templates Object-Oriented Programming Using C++ Second Edition 11.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 11 - Templates Outline 11.1 Introduction 11.2 Function Templates 11.3 Overloading Function Templates.
Fall 2005CSE 115/503 Introduction to Computer Science I1 Composition details Recall, composition involves 3 things: –Declaration of instance variable of.
Templates Outlines 1. Introduction 2. Function Templates 3. Overloading Function Templates 4. Class Templates.
Inheritance using Java
Chapter 5 - Writing a Problem Domain Class Definition1 Chapter 5 Writing a Problem Domain Class Definition.
Templates Zhen Jiang West Chester University
C++ How to Program, 8/e © by Pearson Education, Inc. All Rights Reserved. Note: C How to Program, Chapter 22 is a copy of C++ How to Program Chapter.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 11 - Templates Outline 11.1 Introduction 11.2 Function Templates 11.3 Overloading Function Templates.
EEL 3801 Part VIII Fundamentals of C and C++ Programming Template Functions and Classes.
BPJ444: Business Programming Using Java Classes and Objects Tim McKenna
1 Chapter 3 and 6– Classes, Objects and Methods Object-Oriented Programming Concepts – Read it from Java TutorialJava Tutorial Definition: A class is a.
Object-Oriented Programming (OOP). Implementing an OOD in Java Each class is stored in a separate file. All files must be stored in the same package.
Copyright © 2012 Pearson Education, Inc. Chapter 9 Classes and Multiform Projects.
 Classes in c++ Presentation Topic  A collection of objects with same properties and functions is known as class. A class is used to define the characteristics.
1 Generics Chapter 21 Liang, Introduction to Java Programming.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Templates.
1 Using Templates COSC 1567 C++ Programming Lecture 10.
CSci 162 Lecture 10 Martin van Bommel. Procedures vs Objects Procedural Programming –Centered on the procedures or actions that take place in a program.
COMP 121 Week 8: Generic Collections. Objectives To understand type variables and how they are used in generic programming To be able to implement and.
1 Object-Oriented Programming -- Using C++ Andres, Wen-Yuan Liao Department of Computer Science and Engineering De Lin Institute of Technology
CS212: Object Oriented Analysis and Design Lecture 22: Generic Class Design.
Methods.
Chapter 17 – Templates. Function Templates u Express general form for a function u Example: template for adding two numbers Lesson 17.1 template Type.
An Introduction to Programming with C++ Fifth Edition Chapter 14 Classes and Objects.
Lecture 17: 4/4/2003CS148 Spring CS148 Introduction to Programming II Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
Class Diagrams Revisited. Parameterized Classes Parameterized Classes - are used to represent relationships between templates.
 2006 Pearson Education, Inc. All rights reserved Templates.
Mr H Kandjimi 2016/01/03Mr Kandjimi1 Week 3 –Modularity in C++
OOP Tirgul 10. What We’ll Be Seeing Today  Generics – A Reminder  Type Safety  Bounded Type Parameters  Generic Methods  Generics and Inner Classes.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 7: Introduction to Object- Oriented Programming in Python – Exercises Xiang Lian The University of.
INTRODUCTION TO CLASSES & OBJECTS CREATING CLASSES USING C#
OOP Details Constructors, copies, access. Initialize Fields are not initialized by default:
1 CSE 2341 Object Oriented Programming with C++ Note Set #17.
TK1924 Program Design & Problem Solving Session 2011/2012
Default Constructors A default constructor is a constructor that takes no arguments. If you write a class with no constructor at all, C++ will write a.
Introduction to Object-oriented Program Design
Chapter 11 - Templates Outline Introduction Function Templates Overloading Function Templates Class Templates Class.
Introduction to Programming
Implementing Classes Chapter 3.
Object-Oriented Programming
Object-oriented Design in Processing
User-Defined Classes and ADTs
Chapter 11 - Templates Outline Introduction Function Templates Overloading Function Templates Class Templates Class.
Chapter 8 Classes User-Defined Classes and ADTs
CLASSES AND OBJECTS.
Which best describes the relationship between classes and objects?
Object-Oriented Programming
NAME 436.
Templates Generic Programming.
Classes and Objects CGS3416 Spring 2019.
Chapter 11 - Templates Outline Introduction Function Templates Overloading Function Templates Class Templates Class.
Abstract Data Types Abstraction is to distill a system to its most fundamental parts. Applying the abstraction paradigm to the design of data structures.
Templates Generic Programming.
Presentation transcript:

Class template Describing a generic class Instantiating classes that are type- specific version of this generic class Also are called parameterized types Require one or more type parameters to specify how to customize a generic class

Define template class template class ClassName { public: // constructor void set( T a); T get(); // other functions; private: T x; };

Implementation template Before each function definition template ClassName ::ClassName(){} template ClassName ::set( X a) { x = a;} template Y ClassName ::get(){ return x;}

Use template – main function When create a object of the template class, specify the data type be used for this object in a angle bracket Declare a variable ClassName x; ClassName y;