Introduction to Core C++
|
|
- Phebe Boone
- 5 years ago
- Views:
Transcription
1 Introduction to Core C++ Lecture 04: Template Functions and Template Classes Massimiliano Culpo 1 1 CINECA - SuperComputing Applications and Innovation Department M.Culpo (CINECA) Introduction to C / 19
2 Template declarations Template declarations ( 14) A template defines a family of classes or functions: 1 template <typename T> 2 T const& max (T const& a, T const& b ) { 3 // i f a < b then use b e l s e use a 4 return a < b? b : a ; 5 } A template declaration shall: declare or define a function or a class define a member function, a member class or a static data member define a member template of a class or class template A template declaration is also a definition if its declaration defines a function, a class, or a static data member. M.Culpo (CINECA) Introduction to C / 19
3 Template parameters ( 14.1) Template parameters There are three kinds of allowed template parameters: non-type template parameters, type template parameters and template template parameters. A non-type template parameter shall be either an integral or enumeration type, a pointer/reference to object or function or a pointer to member. 1 template<const X& x, i n t i > void f ( ) { 2 i ++; // e r r o r 3 &x ; // OK 4 &i ; // e r r o r 5 i n t& r i = i ; // e r r o r 6 const i n t& c r i = i ; // OK 7 } A non-type template parameter cannot be assigned to or in any other way have its value changed. M.Culpo (CINECA) Introduction to C / 19
4 Template parameters ( 14.1) Template parameters The keyword class followed by an unqualified-id names a type parameter: 1 template<c l a s s K, c l a s s V> c l a s s Map { 2 std : : vector<k> key ; 3 std : : vector<v> value ; 4 } ; Template classes may also be used as template parameters: 1 template<c l a s s K, c l a s s V, 2 template<c l a s s T> c l a s s C > c l a s s Map { 3 C<K> key ; 4 C<V> value ; 5 } ; M.Culpo (CINECA) Introduction to C / 19
5 Template parameters ( 14.1) Template parameters A default argument may be specified for any kind of template parameter: 1 template<c l a s s T1, c l a s s T2 = int > c l a s s A; 2 3 template <c l a s s T = f l o a t > s t r u c t B { } ; 4 template <template <c l a s s TT = f l o a t > c l a s s T> 5 s t r u c t A { 6 i n l i n e void f ( ) ; 7 i n l i n e void g ( ) ; 8 } ; 9 template <template <c l a s s TT> c l a s s T> 10 void A<T>:: f ( ) { T<> t ; } // e r r o r 11 template <template <c l a s s TT = char> c l a s s T> 12 void A<T>:: g ( ) { T<> t ; } // OK T<char> M.Culpo (CINECA) Introduction to C / 19
6 Function templates Function templates ( ) A function template defines an unbounded set of related functions: 1 // s o r t. hxx 2 template<c l a s s T> void s o r t ( T& input ) ; A function template can be overloaded: 1 with other function templates 2 with normal functions The mere use of a function template can trigger an instantiation: 1 #i n clude s o r t. hxx 2 std : : vector< double > vec ; 3 s o r t ( vec ) ; M.Culpo (CINECA) Introduction to C / 19
7 Function templates Overloading of function templates ( ) 1 // max. hxx 2 3 // maximum of two i n t v a l u e s 4 i n l i n e i n t const& max ( i n t const& a, i n t const& b ) 5 { r e t u r n a<b?b : a ; } 6 7 // maximum of two v a l u e s of any type 8 template <typename T> 9 i n l i n e T const& max (T const& a, T const& b ) 10 { r e t u r n a<b?b : a ; } // maximum of three v a l u e s of any type 13 template <typename T> 14 i n l i n e T const& 15 max (T const& a, T const& b, T const& c ) 16 { r e t u r n max (max( a, b ), c ) ; } M.Culpo (CINECA) Introduction to C / 19
8 Function templates Overloading of function templates ( ) 1 #i n c l u d e max. hxx 2 3 i n t main ( ) { 4 : : max(7, 42, 6 8 ) ; // template f o r three arguments 5 : : max ( 7. 0, ) ; // max<double> 6 : : max( a, b ) ; // max<char> 7 : : max(7, 4 2 ) ; // non template f o r two i n t s 8 : : max<>(7, 4 2 ) ; // max<i n t > 9 : : max<double >(7, 4 2 ) ; // max<double> 10 : : max( a, ) ; // non template f o r two i n t s 11 } M.Culpo (CINECA) Introduction to C / 19
9 Class templates ( ) Class templates A class template defines an unbounded set of related types: 1 template<c l a s s T> c l a s s Array { 2 T v ; 3 i n t sz ; 4 p u b l i c : 5 e x p l i c i t Array ( i n t ) ; 6 T& operator [ ] ( i n t ) ; 7 T& elem ( i n t i ) { r e t u r n v [ i ] ; } 8 } ; A member function may be defined outside the class in which it is declared: 1 template<c l a s s T> T& Array<T>:: operator [ ] ( i n t i ) { 2 i f ( i <0 sz<=i ) e r r o r ( Array : range e r r o r ) ; 3 r e t u r n v [ i ] ; 4 } M.Culpo (CINECA) Introduction to C / 19
10 Class templates ( ) Class templates Similar rules apply to class member: 1 template<c l a s s T> s t r u c t A { c l a s s B; } ; 2 A<i n t >::B b1 ; 3 template<c l a s s T> c l a s s A<T>::B { } ; 4 A<i n t >::B b2 ; For a member function of a class template: 1 Array<i n t > v1 ( 2 0 ) ; 2 Array<dcomplex> v2 ( 3 0 ) ; 3 // Array<i n t >:: operator [ ] ( ) 4 v1 [ 3 ] = 7 ; 5 // Array<dcomplex >:: operator [ ] ( ) 6 v2 [ 3 ] = dcomplex ( 7, 8 ) ; the template arguments are determined by the type of the object for which the member function is called. M.Culpo (CINECA) Introduction to C / 19
11 Member template ( ) Class templates A template can be declared within a class or class template: 1 template<c l a s s T> s t r u c t s t r i n g { 2 3 template<c l a s s T2> 4 i n t compare ( const T2&); 5 6 template<c l a s s T2> 7 s t r i n g ( const s t r i n g <T2>& s ) 8 { /... / } 9 } ; template<c l a s s T> template<c l a s s T2> 12 i n t s t r i n g <T>:: compare ( const T2& s ) 13 { /... / } M.Culpo (CINECA) Introduction to C / 19
12 Class templates Member template ( ) A local class shall not have member templates. A member function template: 1 shall not be virtual 2 does not override a virtual function 1 template <c l a s s T> s t r u c t AA { 2 template <c l a s s C> v i r t u a l void g (C ) ; // e r r o r 3 } ; 4 c l a s s B { 5 v i r t u a l void f ( i n t ) ; 6 } ; 7 c l a s s D : p u b l i c B { 8 template <c l a s s T> void f (T) ; // no o v e r r i d e 9 void f ( i n t i ) { f <>( i ) ; } // o v e r r i d i n g 10 } ; M.Culpo (CINECA) Introduction to C / 19
13 Class templates Class template partial specialization ( ) A class template may be partially specialized: 1 template<c l a s s T1, c l a s s T2, i n t I> 2 c l a s s A { } ; // Primary c l a s s template 3 4 template<c l a s s T, i n t I> 5 c l a s s A<T, T, I> { } ; // #1 6 7 template<c l a s s T1, c l a s s T2, i n t I> 8 c l a s s A<T1, T2, I> { } ; // #2 Each class template partial specialization is a distinct template and definitions shall be provided for its members. M.Culpo (CINECA) Introduction to C / 19
14 The typename keyword ( 14.6) Name resolution The keyword typename clarifies that an identifier is a type: 1 template <c l a s s T> 2 c l a s s A { 3 typename T : : SubType ptr ; 4 /... / 5 } ; Without typename, the expression: 1 T : : SubType ptr ; would be a multiplication of a static member of class T with ptr. In general, typename has to be used whenever a name that depends on a template parameter is a type. M.Culpo (CINECA) Introduction to C / 19
15 The.template construct ( 14.6) Name resolution Consider the following example: 1 template <c l a s s T> c l a s s C { 2 p u b l i c : 3 template<c l a s s U> s t r i n g i f y ( ) ; 4 } 5 6 template<i n t N> 7 void p r i n t (C<N> const& bs ) { 8 cout << bs. template s t r i n g i f y <char >(); 9 } Without that extra use of template, the compiler can t deduce the meaning of the < token. M.Culpo (CINECA) Introduction to C / 19
16 Dependent names ( ) Name resolution If a base class depends on a template parameter, the base class scope is not examined during unqualified name lookup: 1 typedef double A; 2 3 template<c l a s s T> c l a s s B { 4 typedef i n t A; 5 } ; 6 7 template<c l a s s T> s t r u c t X : B<T> { 8 A a ; // a has type double 9 } ; The consequence is that using a name x by itself is not always equivalent to this >x. M.Culpo (CINECA) Introduction to C / 19
17 String literals Template functions Name resolution Q: Can you explain the following behavior? 1 template <typename T> i n l i n e T const& 2 max (T const& a, T const& b ) { 3 return a < b? b : a ; 4 } 5 6 i n t main ( ) { 7 s t r i n g s ; 8 : : max( a p p l e, peach ) ; // OK 9 : : max( a p p l e, tomato ) ; // ERROR 10 : : max( a p p l e, s ) ; // ERROR 11 } M.Culpo (CINECA) Introduction to C / 19
18 Explicit instantiation ( ) Name resolution An empty template argument list can be used to indicate that a given use refers to a specialization of a function template: 1 template <c l a s s T> i n t f (T) ; // #1 2 i n t f ( i n t ) ; // #2 3 i n t k = f ( 1 ) ; // uses #2 4 i n t l = f < >(1); // uses #1 Implicit conversions will be performed if the parameter type contains no parameters that participate in template argument deduction: 1 template<c l a s s T> void f (T) ; 2 c l a s s Complex { 3 Complex ( double ) ; 4 } ; 5 void g ( ) { 6 f<complex >(1); // OK 7 } M.Culpo (CINECA) Introduction to C / 19
19 Summary overview of name resolution Summary: stages of function name resolution When a function name is to be resolved: 1 foo ( 1 2, 4 5 ) ; the C++ machinery goes through a number of codified stages: 1. (compile-time) Name lookup ( 3.4) 2. (compile-time) Template argument deduction ( ) 3. (compile-time) Overload resolution ( 13) 4. (compile-time) Access control ( 11) 5. (run-time) Virtual function resolution ( ) It is important to know the subtleties of each of these stages to avoid common pitfalls. M.Culpo (CINECA) Introduction to C / 19
Introduction to Standard C++
Introduction to Standard C++ Lecture 04: Template Functions and Template Classes Massimiliano Culpo 1 1 CINECA - SuperComputing Applications and Innovation Department 07.04.2014 M.Culpo (CINECA) Introduction
More informationIntroduction to Standard C++
Introduction to Standard C++ Lecture 00: Administravia + Language basics Massimiliano Culpo 1 1 CINECA - SuperComputing Applications and Innovation Department 07.04.2014 M.Culpo (CINECA) Introduction to
More informationTokens, 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 information10. Functions (Part 2)
10.1 Overloaded functions 10. Functions (Part 2) In C++, two different functions can have the same name if their parameters are different; either because they have a different number of parameters, or
More informationAppendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things.
A Appendix Grammar There is no worse danger for a teacher than to teach words instead of things. Marc Block Introduction keywords lexical conventions programs expressions statements declarations declarators
More informationOverload Resolution. Ansel Sermersheim & Barbara Geller ACCU / C++ June 2018
Ansel Sermersheim & Barbara Geller ACCU / C++ June 2018 1 Introduction Definition of Function Overloading Determining which Overload to call How Overload Resolution Works Standard Conversion Sequences
More informationVector and Free Store (Vectors and Arrays)
DM560 Introduction to Programming in C++ Vector and Free Store (Vectors and Arrays) Marco Chiarandini Department of Mathematics & Computer Science University of Southern Denmark [Based on slides by Bjarne
More informationTemplating functions. Comp Sci 1570 Introduction to C++ Administrative notes. Review. Templates. Compiler processing. Functions Overloading
s s in Templating functions Comp Sci 1570 Introduction to Outline s s in 1 2 3 s s in 4 Test 1 grade distribution grade on y, each student on x, sorted by y s s in 50 or below should talk to me. Outline
More informationOverload Resolution. Ansel Sermersheim & Barbara Geller Amsterdam C++ Group March 2019
Ansel Sermersheim & Barbara Geller Amsterdam C++ Group March 2019 1 Introduction Prologue Definition of Function Overloading Determining which Overload to call How Works Standard Conversion Sequences Examples
More informationCS 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 informationBasic Templates Intro
1 Basic Templates Intro C++ is a strongly typed language - there is strict set of rules on what types that variables can have, and when one type can be used as another type. e.g. conversion rules: my_int
More information1/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 informationSFU 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 informationC Pointers. 6th April 2017 Giulio Picierro
C Pointers 6th April 07 Giulio Picierro Functions Return type Function name Arguments list Function body int sum(int a, int b) { return a + b; } Return statement (return keyword
More informationIntermediate Programming, Spring 2017*
600.120 Intermediate Programming, Spring 2017* Misha Kazhdan *Much of the code in these examples is not commented because it would otherwise not fit on the slides. This is bad coding practice in general
More informationGridKa School 2013: Effective Analysis C++ Templates
GridKa School 2013: Effective Analysis C++ Templates Introduction Jörg Meyer, Steinbuch Centre for Computing, Scientific Data Management KIT University of the State of Baden-Wuerttemberg and National Research
More informationAbstract Data Types (ADTs) 1. Legal Values. Client Code for Rational ADT. ADT Design. CS 247: Software Engineering Principles
Abstract Data Types (ADTs) CS 247: Software Engineering Principles ADT Design An abstract data type (ADT) is a user-defined type that bundles together: the range of values that variables of that type can
More informationAdvanced Systems Programming
Advanced Systems Programming Introduction to C++ Martin Küttler September 19, 2017 1 / 18 About this presentation This presentation is not about learning programming or every C++ feature. It is a short
More informationOutline. User-dened types Categories. Constructors. Constructors. 4. Classes. Concrete classes. Default constructor. Default constructor
Outline EDAF50 C++ Programming 4. Classes Sven Gestegård Robertz Computer Science, LTH 2018 1 Classes the pointer this const for objects and members Copying objects friend inline 4. Classes 2/1 User-dened
More informationPolymorphism. Zimmer CSCI 330
Polymorphism Polymorphism - is the property of OOP that allows the run-time binding of a function's name to the code that implements the function. (Run-time binding to the starting address of the code.)
More informationCS 247: Software Engineering Principles. ADT Design
CS 247: Software Engineering Principles ADT Design Readings: Eckel, Vol. 1 Ch. 7 Function Overloading & Default Arguments Ch. 12 Operator Overloading U Waterloo CS247 (Spring 2017) p.1/17 Abstract Data
More informationLecture 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 information3.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 informationComp151. Function Templates & Class Templates
Comp151 Function Templates & Class Templates Function Templates int max(const int& a, const int& b) string max(const string& a, const string& b) We often find a set of functions that look very much alike,
More informationIntroduction to C++ Introduction. Structure of a C++ Program. Structure of a C++ Program. C++ widely-used general-purpose programming language
Introduction C++ widely-used general-purpose programming language procedural and object-oriented support strong support created by Bjarne Stroustrup starting in 1979 based on C Introduction to C++ also
More informationC++ 11 and the Standard Library: Containers, Iterators, Algorithms
and the Standard Library:,, Comp Sci 1575 Outline 1 2 3 4 Outline 1 2 3 4 #i n clude i n t main ( ) { i n t v a l u e 0 = 5 ; // C++ 98 i n t v a l u e 1 ( 5 ) ; // C++ 98 i n t v a
More informationPolymorphism Part 1 1
Polymorphism Part 1 1 What is Polymorphism? Polymorphism refers to a programming language s ability to process objects differently depending on their data type or class. Number person real complex kid
More informationTemplates. Zoltán Porkoláb: C++11/14 1
Templates From macros to templates Parameter deduction, instantiation,specialization Class templates, partial specialization Explicit instantiation Dependent types Scope resolution, lookup Mixins CRTP
More informationCpt 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 informationTemplate Issue Resolutions from the Stockholm Meeting
96-0153/N0971 Template Issue Resolutions from the Stockholm Meeting 1 X3J16/96-0153 WG21/N0971 July 9 th, 1996 John H. Spicer, Edison Design Group Template Issue Resolutions from the Stockholm Meeting
More informationLesson 11: Generic Programming. EE3490E: Programming S1 2018/2019 Dr. Đào Trung Kiên Hanoi Univ. of Science and Technology
Lesson 11: Generic Programming 1 Function templates 2 General Occasionally, we like to write once but have many functions/methods with arguments of different types, instead of writing multiple overloaded
More informationIntroduction to C++ with content from
Introduction to C++ with content from www.cplusplus.com 2 Introduction C++ widely-used general-purpose programming language procedural and object-oriented support strong support created by Bjarne Stroustrup
More informationtemplate <typename T> // unless it s an unqualified pointer struct IsPtr<T *> { enum { r = true }; };
SFINAE Sono Buoni SFINAE In attempting to use function template argument deduction to select among a number of candidate function templates, a C++ compiler may attempt an instantiation that fails on one
More informationCOEN244: Class & function templates
COEN244: Class & function templates Aishy Amer Electrical & Computer Engineering Templates Function Templates Class Templates Outline Templates and inheritance Introduction to C++ Standard Template Library
More informationExpansion statements. Version history. Introduction. Basic usage
Expansion statements Version history Document: P1306R0 Revises: P0589R0 Date: 08 10 2018 Audience: EWG Authors: Andrew Sutton (asutton@uakron.edu) Sam Goodrick (sgoodrick@lock3software.com) Daveed Vandevoorde
More informationG52CPP C++ Programming Lecture 13
G52CPP C++ Programming Lecture 13 Dr Jason Atkin http://www.cs.nott.ac.uk/~jaa/cpp/ g52cpp.html 1 Last lecture Function pointers Arrays of function pointers Virtual and non-virtual functions vtable and
More informationAdvanced C++ Topics. Alexander Warg, 2017
www.kernkonzept.com Advanced C++ Topics Alexander Warg, 2017 M I C R O K E R N E L M A D E I N G E R M A N Y Overview WHAT IS BEHIND C++ Language Magics Object Life Time Object Memory Layout INTRODUCTION
More informationAn Alternative to Name Injection from Templates
Document Numbers: X3J16/95-0177 WG21/N0777 Date: September 26, 1995 Reply To: Bill Gibbons bgibbons@taligent.com An Alternative to Name Injection from Templates Introduction The current working paper specifies
More informationC The new standard
C++11 - The new standard Lars Kühne Institut für Informatik Lehrstuhl für theoretische Informatik II Friedrich-Schiller-Universität Jena January 16, 2013 Overview A little bit of history: C++ was initially
More informationC++ Important Questions with Answers
1. Name the operators that cannot be overloaded. sizeof,.,.*,.->, ::,? 2. What is inheritance? Inheritance is property such that a parent (or super) class passes the characteristics of itself to children
More informationENERGY 211 / CME 211. Functions
ENERGY 211 / CME 211 Lecture 8 October 8, 2008 1 Functions So far, we have seen programs in which all code resides within a main function Complex programs consist of subprograms that perform particular
More informationCAAM 420 Fall 2012 Lecture 29. Duncan Eddy
CAAM 420 Fall 2012 Lecture 29 Duncan Eddy November 7, 2012 Table of Contents 1 Templating in C++ 3 1.1 Motivation.............................................. 3 1.2 Templating Functions........................................
More informationWhat is Polymorphism? Quotes from Deitel & Deitel s. Why polymorphism? How? How? Polymorphism Part 1
Polymorphism Part 1 What is Polymorphism? Polymorphism refers to a programming language s ability to process objects differently depending on their data type or class. Number person real complex kid adult
More informationAmerican National Standards Institute Reply to: Josee Lajoie
Accredited Standards Committee X3 Information Processing Systems Operating under the procedures of American National Standards Institute Doc No: X3J16/95-0051 WG21/N0651 Date: March 3, 1995 Page 1 of 15
More informationShort 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 informationCS201 - 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 informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationArrays. Comp Sci 1570 Introduction to C++ Array basics. arrays. Arrays as parameters to functions. Sorting arrays. Random stuff
and Arrays Comp Sci 1570 Introduction to C++ Outline and 1 2 Multi-dimensional and 3 4 5 Outline and 1 2 Multi-dimensional and 3 4 5 Array declaration and An array is a series of elements of the same type
More informationModules:Dependent ADL
Document Number: P0923r1 Date: 2018-05-04 To: SC22/WG21 EWG Reply to: Nathan Sidwell nathan@acm.org / nathans@fb.com Re: Working Draft, Extensions to C ++ for Modules, n4720 Modules:Dependent ADL Nathan
More informationC++ Addendum: Inheritance of Special Member Functions. Constructors Destructor Construction and Destruction Order Assignment Operator
C++ Addendum: Inheritance of Special Member Functions Constructors Destructor Construction and Destruction Order Assignment Operator What s s Not Inherited? The following methods are not inherited: Constructors
More informationModules: Contexts of Template Instantiations and Name Lookup Gabriel Dos Reis Microsoft
Modules: Contexts of Template Instantiations and Name Lookup Gabriel Dos Reis Microsoft Background One of the design principles behind modules is to ensure that the working programmer does not need to
More informationStructured bindings with polymorphic lambas
1 Introduction Structured bindings with polymorphic lambas Aaryaman Sagar (aary800@gmail.com) August 14, 2017 This paper proposes usage of structured bindings with polymorphic lambdas, adding them to another
More informationObject Oriented Design
Object Oriented Design Chapter 6 Example Activity Diagram 1 Outline Chapter 6 Topics 6.6 C++ Standard Library Header Files 6.14 Inline Functions 6.16 Default Arguments 6.17 Unary Scope Resolution Operator
More informationPointer Basics. Lecture 13 COP 3014 Spring March 28, 2018
Pointer Basics Lecture 13 COP 3014 Spring 2018 March 28, 2018 What is a Pointer? A pointer is a variable that stores a memory address. Pointers are used to store the addresses of other variables or memory
More informationAbout Codefrux While the current trends around the world are based on the internet, mobile and its applications, we try to make the most out of it. As for us, we are a well established IT professionals
More informationOBJECT ORIENTED PROGRAMMING USING C++
OBJECT ORIENTED PROGRAMMING USING C++ Overview of C++ Overloading Overloading occurs when the same operator or function name is used with different signatures Both operators and functions can be overloaded
More informationC Praktikum. Advanced Pointers. Eugen Betke, Nathanael Hübbe, Michael Kuhn, Jakob Lüttgau, Jannek Squar
C Praktikum Advanced Pointers Eugen Betke, Nathanael Hübbe, Michael Kuhn, Jakob Lüttgau, Jannek Squar 2018-11-26 Warning This is a dive under the hood. We will see, and hopefully understand many details
More informationC++ Programming: Polymorphism
C++ Programming: Polymorphism 2018 년도 2 학기 Instructor: Young-guk Ha Dept. of Computer Science & Engineering Contents Run-time binding in C++ Abstract base classes Run-time type identification 2 Function
More informationType systems. Static typing
Type system A type is a set of values and operations on those values A language s type system specifies which operations are valid for a type The aim of type checking is to ensure that operations are used
More informationCPSC 427: Object-Oriented Programming
CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 20 November 14, 2016 CPSC 427, Lecture 20 1/19 Templates Casts and Conversions CPSC 427, Lecture 20 2/19 Templates CPSC 427, Lecture 20
More informationTDDD38 - Advanced programming in C++
TDDD38 - Advanced programming in C++ Templates III Christoffer Holm Department of Computer and information science 1 Dependent Names 2 More on Templates 3 SFINAE 1 Dependent Names 2 More on Templates 3
More informationUEE1303(1070) S 12 Object-Oriented Programming in C++
Computational Intelligence on Automation Lab @ NCTU UEE1303(1070) S 12 Object-Oriented Programming in C++ Lecture 10: Templates Function Templates And Class Templates Learning Objectives (1/2) Learn about
More informationRvalue References as Funny Lvalues
I. Background Document: Author: Date: 2009-11-09 Revision: 1 PL22.16/09-0200 = WG21 N3010 William M. Miller Edison Design Group Rvalue References as Funny Lvalues Rvalue references were introduced into
More informationInterview Questions of C++
Interview Questions of C++ Q-1 What is the full form of OOPS? Ans: Object Oriented Programming System. Q-2 What is a class? Ans: Class is a blue print which reflects the entities attributes and actions.
More informationCMSC 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 informationChapter 1 INTRODUCTION SYS-ED/ COMPUTER EDUCATION TECHNIQUES, INC.
hapter 1 INTRODUTION SYS-ED/ OMPUTER EDUATION TEHNIQUES, IN. ++ Programming: Advanced Objectives You will learn: Anonymous class types. Nested class declarations. Incomplete declarations. Pointers to class
More informationSoftware Engineering Concepts: Invariants Silently Written & Called Functions Simple Class Example
Software Engineering Concepts: Invariants Silently Written & Called Functions Simple Class Example CS 311 Data Structures and Algorithms Lecture Slides Friday, September 11, 2009 continued Glenn G. Chappell
More informationOverview. 1. Expression Value Categories 2. Rvalue References 3. Templates 4. Miscellaneous Hilarity 2/43
Advanced C++ 1/43 Overview 1. Expression Value Categories 2. Rvalue References 3. Templates 4. Miscellaneous Hilarity 2/43 1. Expression Value Categories These are not the droids you re looking for ~Obi-wan
More informationMARKING 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 informationSemantics of C++ Hauptseminar im Wintersemester 2009/10 Templates
Semantics of C++ Hauptseminar im Wintersemester 2009/10 Templates Sebastian Wild Technische Universität München 11.01.2010 Abstract In this work we will discuss about templates in C++, especially their
More informationObject Oriented Design Final Exam (From 3:30 pm to 4:45 pm) Name:
Object Oriented Design Final Exam (From 3:30 pm to 4:45 pm) Name: Section 1 Multiple Choice Questions (40 pts total, 2 pts each): Q1: Employee is a base class and HourlyWorker is a derived class, with
More informationMotivation for Templates
Motivation for You want both: a list of Location objects a list of MazeMonster objects 1 How can you accomplish this by writing one LinkedList class? state all the ways you can think of doing this state
More informationCS93SI Handout 04 Spring 2006 Apr Review Answers
CS93SI Handout 04 Spring 2006 Apr 6 2006 Review Answers I promised answers to these questions, so here they are. I'll probably readdress the most important of these over and over again, so it's not terribly
More informationC++ Module TS Issues List Gabriel Dos Reis Microsoft
P0501R3 2018-01-30 Reply-To: gdr@microsoft.com Active Issues C++ Module TS Issues List Gabriel Dos Reis Microsoft [5] Static local variables [John Spicer, 11/8/2016] Should there be a restriction on local
More informationOperator Overloading and Templates. Linear Search. Linear Search in C++ second attempt. Linear Search in C++ first attempt
Operator Overloading and Templates Week 6 Gaddis: 8.1, 14.5, 16.2-16.4 CS 5301 Fall 2015 Jill Seaman Linear Search! Search: find a given target item in an array, return the index of the item, or -1 if
More informationPaytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value
Paytm Programming Sample paper: 1) A copy constructor is called a. when an object is returned by value b. when an object is passed by value as an argument c. when compiler generates a temporary object
More informationTopics. bool and string types input/output library functions comments memory allocation templates classes
C++ Primer C++ is a major extension of c. It is similar to Java. The lectures in this course use pseudo-code (not C++). The textbook contains C++. The labs involve C++ programming. This lecture covers
More informationA student was asked to point out interface elements in this code: Answer: cout. What is wrong?
A student was asked to point out interface elements in this code: Answer: cout. What is wrong? Clarification of the concept of INTERFACE The interface we ve been talking about in OOP is not the man-machine
More informationGoals of this Lecture
C Pointers Goals of this Lecture Help you learn about: Pointers and application Pointer variables Operators & relation to arrays 2 Pointer Variables The first step in understanding pointers is visualizing
More informationCOMP6771 Advanced C++ Programming
1.. COMP6771 Advanced C++ Programming Week 6 Part One: Function Templates 2016 www.cse.unsw.edu.au/ cs6771 2.. Constants Two notions of immutability: const: A promise not to change this value. Used primarily
More information! Search: find a given target item in an array, ! Linear Search: Very simple search method: ! Operators such as =, +, <, and others can be
Operator Overloading and Templates Week 6 Gaddis: 8.1, 14.5, 16.2-16.4 CS 5301 Spring 2015 Jill Seaman Linear Search! Search: find a given target item in an array, return the index of the item, or -1 if
More informationCS11 Advanced C++ Fall Lecture 7
CS11 Advanced C++ Fall 2006-2007 Lecture 7 Today s Topics Explicit casting in C++ mutable keyword and const Template specialization Template subclassing Explicit Casts in C and C++ C has one explicit cast
More informationWorking Draft, Extensions to C++ for Modules
Document Number: Date: 2017-03-19 Revises: N4637 Reply to: Gabriel Dos Reis Microsoft gdr@microsoft.com Working Draft, Extensions to C++ for Modules Note: this is an early draft. It s known to be incomplet
More informationAdvanced C++ Programming Workshop (With C++11, C++14, C++17) & Design Patterns
Advanced C++ Programming Workshop (With C++11, C++14, C++17) & Design Patterns This Advanced C++ Programming training course is a comprehensive course consists of three modules. A preliminary module reviews
More informationLecture #23: Conversion and Type Inference
Lecture #23: Conversion and Type Inference Administrivia. Due date for Project #2 moved to midnight tonight. Midterm mean 20, median 21 (my expectation: 17.5). Last modified: Fri Oct 20 10:46:40 2006 CS164:
More informationG Programming Languages - Fall 2012
G22.2110-003 Programming Languages - Fall 2012 Lecture 4 Thomas Wies New York University Review Last week Control Structures Selection Loops Adding Invariants Outline Subprograms Calling Sequences Parameter
More informationAssignment #1 Advanced Programming in C /2018. NPRG051 Advanced programming in C++ - Assignment #1
Assignment #1 Advanced Programming in C++ 2017/2018 1 Assignment #1 split deadline: Thu 12 Apr 23:59 2 using namespace splitter; std::istringstream iss("alpha:=10/50.1"); std::string x; int y; double z;
More informationConversion vs. Subtyping. Lecture #23: Conversion and Type Inference. Integer Conversions. Conversions: Implicit vs. Explicit. Object x = "Hello";
Lecture #23: Conversion and Type Inference Administrivia. Due date for Project #2 moved to midnight tonight. Midterm mean 20, median 21 (my expectation: 17.5). In Java, this is legal: Object x = "Hello";
More informationProposed Wording for Variadic Templates (Revision 1)
Proposed Wording for Variadic Templates (Revision 1) Authors: Douglas Gregor, Indiana University Jaakko Järvi, Texas A&M University Jens Maurer Jason Merrill, Red Hat Document number: N2191=07-0051 Revises
More informationProposed Wording for Variadic Templates
Proposed Wording for Variadic Templates Authors: Douglas Gregor, Indiana University Jaakko Järvi, Texas A&M University Jens Maurer Jason Merrill, Red Hat Document number: N2152=07-0012 Revises document
More informationPolymorphism. Contents. Assignment to Derived Class Object. Assignment to Base Class Object
Polymorphism C++ Object Oriented Programming Pei-yih Ting NTOU CS 26-1 Contents Assignment to base / derived types of objects Assignment to base / derived types of pointers Heterogeneous container and
More informationC++ (Non for C Programmer) (BT307) 40 Hours
C++ (Non for C Programmer) (BT307) 40 Hours Overview C++ is undoubtedly one of the most widely used programming language for implementing object-oriented systems. The C++ language is based on the popular
More informationLecture 7: Type Systems and Symbol Tables. CS 540 George Mason University
Lecture 7: Type Systems and Symbol Tables CS 540 George Mason University Static Analysis Compilers examine code to find semantic problems. Easy: undeclared variables, tag matching Difficult: preventing
More informationGeneralized pointer casts
Contents Doc No: N3235=11-0005 Date: 2011-02-23 Authors: Pablo Halpern Intel Corp.. phalpern@halpernwightsoftware.com Generalized pointer casts National Body Comments and Issues... 1 Document Conventions...
More informationDeducing the type of variable from its initializer expression (revision 3)
Deducing the type of variable from its initializer expression (revision 3) Programming Language C++ Document no: N1894=05-0154 Jaakko Järvi Texas A&M University College Station, TX jarvi@cs.tamu.edu Bjarne
More information! Operators such as =, +, <, can be defined to. ! The function names are operator followed by the. ! Otherwise they are like normal member functions:
Operator Overloading, Lists and Templates Week 6 Gaddis: 14.5, 16.2-16.4 CS 5301 Spring 2016 Jill Seaman Operator Overloading! Operators such as =, +,
More informationuse static size for this buffer
Software Design (C++) 4. Templates and standard library (STL) Juha Vihavainen University of Helsinki Overview Introduction to templates (generics) std::vector again templates: specialization by code generation
More informationProject Compiler. CS031 TA Help Session November 28, 2011
Project Compiler CS031 TA Help Session November 28, 2011 Motivation Generally, it s easier to program in higher-level languages than in assembly. Our goal is to automate the conversion from a higher-level
More informationWhat is an algorithm?
Announcements CS 142 Inheritance/Polymorphism Wrapup Program 8 has been assigned - due Tuesday, Dec. 9 th by 11:55pm 11/21/2014 2 Definitions Class: description of a data type that can contain fields (variables)
More informationC++ C and C++ C++ fundamental types. C++ enumeration. To quote Bjarne Stroustrup: 5. Overloading Namespaces Classes
C++ C and C++ 5. Overloading Namespaces Classes Alastair R. Beresford University of Cambridge Lent Term 2007 To quote Bjarne Stroustrup: C++ is a general-purpose programming language with a bias towards
More information