The c ++ Programming Language Lecture 6 OOP With Templates
The C++ Programming Language Lecture 6: OOP with Templates
Basic Concepts and Syntaxes
Basic Concepts and Syntaxes
Template u Original name-Parameterized Types Parameterized-Abstracted data type information from Implementation Type- For every class template or function template, there are different features and characters when bound to different data pes, they act like a type Template generate a function or class automatically according to the value or type user specified string, vector, list are all class templates, and we will implement our template in this lecture
Template ◼ Original name – Parameterized Types ◼ Parameterized – Abstracted data type information from implementation ◼ Type – For every class template or function template, there are different features and characters when bound to different data types, they act like a type ◼ Template generate a function or class automatically, according to the value or type user specified ◼ string, vector, list are all class templates, and we will implement our template in this lecture
Starting Point-the binary tree class Piglet Root Eeyore RoO Left child Right child Chris K anga Pooh Tigger Operations that need to be provided Insert, remove Find, clear Print(preorder, inorder, postorder) Preorder: Piglet, Eeyore, Chris, Kanga, Roo, Pooh, Tigger Inorder: Chris, Eeyore, Kanga, Piglet, Pooh, Roo, Tigger Postorder: Chris Kanga, Eeyore, pooh, Tigger, roo piglet
Starting Point – the binary tree class ◼ Operations that need to be provided ◼ Insert, remove ◼ Find, clear ◼ Print (preorder, inorder, postorder) – Preorder: Piglet, Eeyore, Chris, Kanga, Roo, Pooh, Tigger – Inorder: Chris, Eeyore, Kanga, Piglet, Pooh, Roo, Tigger – Postorder: Chris, Kanga, Eeyore, Pooh, Tigger, Roo, Piglet Piglet Roo Pooh Tigger Right child Eeyore Chris Kanga Left child Root
The binary tree class 2 classes BinaryTree- storing only one pointer pointing to the root BINode-storing the value of node and links to left and right childs We provide a non-template BTNode class declaration class string BTNode p pI rivate string m szVal nt m iCnt string btNode* Child string btnode* rchild };
The binary tree class ◼ 2 classes ◼ BinaryTree – storing only one pointer pointing to the root ◼ BTNode – storing the value of node and links to left and right childs ◼ We provide a non-template BTNode class declaration class string_BTNode { public: //… private: string m_szVal; int m_iCnt; string_BTNode* lchild; string_BTNode* rchild; };