C The new standard

Size: px
Start display at page:

Download "C The new standard"

Transcription

1 C The new standard Lars Kühne Institut für Informatik Lehrstuhl für theoretische Informatik II Friedrich-Schiller-Universität Jena January 16, 2013

2 Overview A little bit of history: C++ was initially developed by Bjarne Stroustrup in 1979 first ISO Standard in 1998 replaced by the corrigendum C++03 in 2003 (only bug fixes for the implementors) early draft in 2005: technical report 1 (TR1) next (and current) standard release in August, 2011: C++11 Surprisingly, C++11 feels like a new language - the pieces just fit together better. Bjarne Stroustrup

3 Things you won t miss std::auto ptr: got replaced by std::unique ptr the export keyword was supposed to allow separation of declaration and definition of templates no major compiler support still reserved dynamic exception specifications by default every function can throw anything exceptions specifications allow to restrict that not enforced at compile-time, hard to use correctly

4 Getting started recognize >> as closing a template declaration, instead of > > new keyword: noexcept void f o o ( ) n o e x c e p t ; a guarantee by the programmer to the compiler to guide optimizations compile-time assertions: static assert Example (static assert) template <typename T> void bar ( const T& x ) { s t a t i c a s s e r t ( s t d : : i s i n t e g r a l <T>:: v a l u e, T must be i n t e g r a l ) ; // do some a r i t h m e t i c... }

5 default, delete, final and override Example c l a s s A { p u b l i c : A( ) = d e f a u l t ; A( const A&) = d e l e t e ; v i r t u a l void f o o ( ) {} v i r t u a l void bar ( ) f i n a l {} } ; c l a s s B : p u b l i c A f i n a l { p u b l i c : v i r t u a l void f o o ( ) o v e r r i d e ; v i r t u a l void bar ( ) ; // e r r o r } ; c l a s s C : p u b l i c B ; // e r r o r

6 Extern templates Example in C++03 the compiler is required to instantiate every fully-specified template this may result in long compilation times, if the same template gets instantiated in different translation units // h e a d e r template <typename T> c l a s s Foo {/ compile time e x p e n s i v e d e f i n i t i o n / } ; // s o u r c e 1. o auto x = Foo<double >(); // s o u r c e 2. o > c o m p i l e s f o r a 2nd time! auto x = Foo<double >(); // s o u r c e 2 e x t e r n. o > no i n s t a n t i a t i o n o f Foo<double > extern template c l a s s Foo<double >; auto x = Foo<double >();

7 The problem with NULL Example as inherited by C, NULL is a Makro usually expanding to 0 void f o o ( i n t ) ; void f o o ( char ) ; // c a l l f o o (NULL ) ; new null-pointer constant: std::nullptr implicitely convertible and comparable to any pointer type not so for integral types, except for bool

8 The auto keyword old keyword with new meaning tells the compiler to deduce the type of the variable from its initialization i n t x = 4 ; // C++98 auto x = 4 ; // C++11 Serves as a convenience in cases where the type is either hard to write... s t d : : map<i n t, s t d : : v e c t o r <double> > my map ; // C++98 s t d : : map<i n t, s t d : : v e c t o r <double> >:: c o n s t i t e r a t o r i t = my map. b e g i n ( ) ; // C++11 auto i t = my map. c b e g i n ( ) ;

9 The auto keyword...or hard to know template <c l a s s A, c l a s s B> void f o o ( const A& a, const B& b ) { auto tmp = a b ; } // c a l l i n g the f u n c t i o n f o o ( u, v ) ; Inconvenient C++98 solution: template <c l a s s A, c l a s s B, c l a s s C> void f o o ( const A& a, const B& b ) { C tmp = a b ; } // c a l l i n g the f u n c t i o n foo<w>(u, v ) ;

10 The auto keyword strips off const-ness and references i n t a = 4 2 ; const i n t& b = a ; auto c = b ; // i n t // e x p l i c i t e l y add on q u a l i f i e r s const auto& d = c ; // c o n s t i n t& pointers, however, are treated as types of their own i n t a p t r = &a ; auto b p t r = a p t r ; // i n t auto c p t r = a p t r ; // i n t

11 The auto keyword and return-types return-types can be auto as well auto f o o ( ) > i n t { r e t u r n 4 ; } requires the programmer to provide a trailing-return-type template <c l a s s A, c l a s s B> auto f o o ( const A& a, const B& b ) > d e c l t y p e ( a b ) { r e t u r n a b ; } decltype is a new compile-time operator that returns the type of the given expression trailing-return-type especially useful with multiple return-statements (std::common type)

12 Range-based for-loop Example allows for a more compact way to express an iteration over a range an object is a range, if 1 its type either has the members begin() and end() returning valid iterators 2 or there are functions begin(obj) and end(obj) doing so all STL containers, regular-expression matches and initializer lists are iterable using range-based for loops s t d : : v e c t o r <i n t > v ; //... f i l l v... f o r ( i n t i : v ) s t d : : cout << i << s t d : : e n d l ; f o r ( auto& i : v ) // c o n s t a l s o p o s s i b l e i = i i ;

13 Lambda functions Example (What s wrong with this picture?) c l a s s SquareFunctor { p u b l i c : template <typename S c a l a r > S c a l a r operator ( ) ( const S c a l a r v a l u e ) { r e t u r n v a l u e v a l u e ; } } ; template <c l a s s I t e r a t o r > void s q u a r e ( I t e r a t o r begin, I t e r a t o r end ) { SquareFunctor mysquarefunctor ; s t d : : f o r e a c h ( begin, end, mysquarefunctor ) ; } a lot of code to square a number required a named entity for a one-liner

14 Lambda functions Example template <c l a s s I t e r a t o r > void s q u a r e ( I t e r a t o r begin, I t e r a t o r end ) s t d : : f o r e a c h ( begin, end, [ ] ( double v a l u e ) { r e t u r n v a l u e v a l u e ; } ) ; Definition (Lambda) 1 capture []: wildcard & and =, or named variables from scope 2 function body {} 3 no return type: is deduced by the compiler 4 optional: trailing return-type 5 under the hood: the compiler defines and intantiates a full-fledged function object

15 Lambda functions Example s t d : : map<i n t, s t d : : s t r i n g > mymap ; const i n t i d x = 3 ; // f i l l map... // the c o m p i l e r c a p t u r e s a l l the v a r i a b l e s // used i n the body by r e f e r e n c e auto lambda 1 = [&] ( ) { r e t u r n mymap [ i d x ]. s i z e ( ) > 0 } ; // copy the idx, but c a p t u r e the map by r e f e r e n c e auto lambda 2 = [=,&mymap ] ( ) { r e t u r n mymap [ i d x ]. s i z e ( ) > 0 } ; // c a l l the lambda i f ( lambda 1 ( ) ) e x i t ( EXIT SUCCESS ) ; convenient inline function-declaration C++11-lambdas are not polymorphic (yet)

16 Rvalue references Example motivation: avoid creating temporaries s t d : : v e c t o r <s t d : : s t r i n g > v ; v. push back ( C++11 ) ; 1 implicitely: calls std::string(const char*) this creates the temporary! 2 calls v.push back(const std::string&) this appends a copy of the temporary 3 implicitely: calls std::string:: string() on the temporary unnecessary constructor and destructor call

17 Rvalue references idea: reuse the temporary for the final result What makes a temporary/rvalue? Definition (Lvalues and Rvalues) inspired by the side of = they are usually found i n t n = 3 ; // n i s an l v a l u e 5 = n + 7 ; // 5 i s an r v a l u e ( compile time e r r o r ) lvalues (their address) still exists after the statement rvalues do not exist anymore after the statement (even though one might have kept the address)

18 Rvalue references are defined with && mutable rvalues (exclusively!) bind to rvalue-references special treatment for temporaries binding-rules & const & && const && lvalue x x x x const-lvalue x x rvalue x x x const-rvalue x x

19 Rvalue references Example (Overload resolution) void f o o ( s t d : : s t r i n g &); void f o o ( const s t d : : s t r i n g &); void f o o ( s t d : : s t r i n g &&); void f o o ( const s t d : : s t r i n g &&); f o o ( l v a l u e ) ; // v o i d f o o ( s t d : : s t r i n g &); f o o ( c o n s t l v a l u e ) ; // v o i d f o o ( c o n s t s t d : : s t r i n g &); f o o ( r v a l u e ) ; // v o i d f o o ( s t d : : s t r i n g &&); f o o ( c o n s t r v a l u e ) ; // v o i d f o o ( c o n s t s t d : : s t r i n g &&); Easy rules: rvalues prefer rvalue-references lvalues prefer lvalue-references must respect const-ness

20 Rvalue references 1 in practice: const & und && 2 copy-/move-constructors and assignment-operators 3 the compiler recognizes temporaries by resolving them to &&-overloads basis for move semantic Example (Move-semantic methods) c l a s s Foo { p u b l i c : Foo ( ) ; Foo ( const Foo &); Foo& operator=(const Foo &); // move c o n s t r. and assignment op. Foo ( Foo&&); Foo& operator=(foo&&); } ; Foo x ( Foo ( ) ) ; // c a l l s Foo ( Foo&&)

21 Rvalue references Example (Move Semantics) c l a s s AlsoMovable { } ; c l a s s Moveable { p u b l i c : Moveable ( s t d : : s i z e t s i z e ) : b i g A r r a y (new double [ s i z e ] ) {} } Moveable ( Moveable&& o t h e r ) : b i g A r r a y ( o t h e r. b i g A r r a y ), am ( s t d : : move ( o t h e r. am) ) { o t h e r. b i g A r r a y = s t d : : n u l l p t r ; } Moveable ( ) { d e l e t e b i g A r r a y ; } p r i v a t e double b i g A r r a y ; AlsoMovable am ;

22 Rvalue references rvalue-references are useful when there is more to move than just basic data types (int, float, pointers,...) big chunks of dynamically allocated memory (moveable) members of some other class type the STL is now move-enabled: container-classes provide move-insertion std::unique ptr is move-only not every moveable can be detected by the compiler Example (user-guided moving) template <c l a s s T> void swap (T& x, T& y ) { T tmp ( s t d : : move ( x ) ) ; x = s t d : : move ( y ) ; y = s t d : : move ( tmp ) ; } std::move turns lvalue-references into rvalue-references

23 Variadic Templates templates can now have an arbitrary number of arbitrary types Definition (Parameter Pack) indicated with the ellipsis operator:... 1 Template: holds variadic template parameters 2 Function: holds the corresponding function arguments Example template <c l a s s... Types> c l a s s t u p l e ; template <c l a s s T, c l a s s... Args> s t d : : s h a r e d p t r <T> make shared ( Args &&... a r g s ) ; template <c l a s s T, s t d : : s i z e t... Dims> c l a s s MultiDimArray ;

24 Variadic Templates - Unpacking:... Example template <c l a s s... Args> c l a s s CountArgs ; template <c l a s s T, c l a s s... Args> c l a s s CountArgs<T, Args... > { p u b l i c : const s t a t i c i n t v a l u e = CountArgs<Args... > : : v a l u e + 1 ; } ; // no arguments matches, t o o template <> c l a s s CountArgs<> { p u b l i c : const s t a t i c i n t v a l u e = 0 ; } ; CountArgs<i n t, f l o a t, double >:: v a l u e ; // 3 sizeof...(args) does the same

25 Variadic Templates - Unpacking patterns Example the...-operator unpacks every element according to the pattern to its left template <c l a s s T, c l a s s... Rest> // add c o n s t and & to each element o f Rest void p r i n t ( const T& obj, const Rest &... r e s t ) { s t d : : cout << o b j ; // don t add a n y t h i n g to r e s t p r i n t ( r e s t... ) ; } template <c l a s s F, c l a s s... Types> void c a l l (F foo, const Types &... t y p e s ) { // t r a n s l a t e s i n t o : f o o ( bar ( t y p e s 1 ), bar ( t y p e s 2 ),... ) f o o ( bar ( t y p e s )... ) ; }

26 Still more polymorphic function-wrappers type-traits for meta-programming comprehensive number-generation facilitiy regular expressions hash-based unordered containers user-defined literals, initializer lists,... The ISO plans on publishing the next revision C++1y until There is now an official community website: isocpp.org

27 Thank you! Questions? Overview of the new C++(C++11) - Scott Meyers C the final draft (N3337) - ISO cppreference.com, cplusplus.com

C++11 and Compiler Update

C++11 and Compiler Update C++11 and Compiler Update John JT Thomas Sr. Director Application Developer Products About this Session A Brief History Features of C++11 you should be using now Questions 2 Bjarne Stroustrup C with Objects

More information

CS

CS CS 1666 www.cs.pitt.edu/~nlf4/cs1666/ Programming in C++ First, some praise for C++ "It certainly has its good points. But by and large I think it s a bad language. It does a lot of things half well and

More information

C++11/14 Rocks. Clang Edition. Alex Korban

C++11/14 Rocks. Clang Edition. Alex Korban C++11/14 Rocks Clang Edition Alex Korban 1 Contents Introduction 9 C++11 guiding principles... 9 Type Inference 11 auto... 11 Some things are still manual... 12 More than syntactic sugar... 12 Why else

More information

Structured bindings with polymorphic lambas

Structured 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 information

C++11 Introduction to the New Standard. Alejandro Cabrera February 1, 2012 Florida State University Department of Computer Science

C++11 Introduction to the New Standard. Alejandro Cabrera February 1, 2012 Florida State University Department of Computer Science C++11 Introduction to the New Standard Alejandro Cabrera February 1, 2012 Florida State University Department of Computer Science Overview A Brief History of C++ Features Improving: Overall Use Meta-programming

More information

Rvalue References & Move Semantics

Rvalue References & Move Semantics Rvalue References & Move Semantics PB173 Programming in Modern C++ Nikola Beneš, Vladimír Štill, Jiří Weiser Faculty of Informatics, Masaryk University spring 2016 PB173 Modern C++: Rvalue References &

More information

Object-Oriented Principles and Practice / C++

Object-Oriented Principles and Practice / C++ Object-Oriented Principles and Practice / C++ Alice E. Fischer May 13, 2013 OOPP / C++ Lecture 7... 1/27 Construction and Destruction Allocation and Deallocation Move Semantics Template Classes Example:

More information

Lesson 13 - Vectors Dynamic Data Storage

Lesson 13 - Vectors Dynamic Data Storage Lesson 13 - Vectors Dynamic Data Storage Summary In this lesson we introduce the Standard Template Library by demonstrating the use of Vectors to provide dynamic storage of data elements. New Concepts

More information

Advanced Systems Programming

Advanced 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 information

Object-Oriented Principles and Practice / C++

Object-Oriented Principles and Practice / C++ Object-Oriented Principles and Practice / C++ Alice E. Fischer October 10, 2016 OOPP / C++ Lecture 7... 1/15 Construction and Destruction Kinds of Constructors Move Semantics OOPP / C++ Lecture 7... 2/15

More information

Interview Questions of C++

Interview 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 information

Object-Oriented Programming

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

More information

G52CPP C++ Programming Lecture 20

G52CPP C++ Programming Lecture 20 G52CPP C++ Programming Lecture 20 Dr Jason Atkin http://www.cs.nott.ac.uk/~jaa/cpp/ g52cpp.html 1 Wrapping up Slicing Problem Smart pointers More C++ things Exams 2 The slicing problem 3 Objects are not

More information

QUIZ. What is wrong with this code that uses default arguments?

QUIZ. What is wrong with this code that uses default arguments? QUIZ What is wrong with this code that uses default arguments? Solution The value of the default argument should be placed in either declaration or definition, not both! QUIZ What is wrong with this code

More information

Object-Oriented Principles and Practice / C++

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

More information

Rvalue References, Move Semantics, Universal References

Rvalue References, Move Semantics, Universal References Rvalue References, Move Semantics, Universal References PV264 Advanced Programming in C++ Nikola Beneš Jan Mrázek Vladimír Štill Faculty of Informatics, Masaryk University Spring 2018 PV264: Rvalue References,

More information

Introduction to Move Semantics in C++ C and C

Introduction to Move Semantics in C++ C and C Introduction to Move Semantics in C++ C++ 2011 and C++ 2014 Jean-Paul RIGAULT University of Nice - Sophia Antipolis Engineering School Computer Science Department Sophia Antipolis, France Contents of the

More information

Note 12/1/ Review of Inheritance Practice: Please write down 10 most important facts you know about inheritance...

Note 12/1/ Review of Inheritance Practice: Please write down 10 most important facts you know about inheritance... CISC 2000 Computer Science II Fall, 2014 Note 12/1/2014 1 Review of Inheritance Practice: Please write down 10 most important facts you know about inheritance... (a) What s the purpose of inheritance?

More information

September 10,

September 10, September 10, 2013 1 Bjarne Stroustrup, AT&T Bell Labs, early 80s cfront original C++ to C translator Difficult to debug Potentially inefficient Many native compilers exist today C++ is mostly upward compatible

More information

Advanced Programming & C++ Language

Advanced Programming & C++ Language Advanced Programming & C++ Language ~10~ C++11 new features Ariel University 2018 Dr. Miri (Kopel) Ben-Nissan 2 Evolution of C++ Language What is C++11? 3 C++11 is the ISO C++ standard formally ratified

More information

C++11: 10 Features You Should be Using. Gordon R&D Runtime Engineer Codeplay Software Ltd.

C++11: 10 Features You Should be Using. Gordon R&D Runtime Engineer Codeplay Software Ltd. C++11: 10 Features You Should be Using Gordon Brown @AerialMantis R&D Runtime Engineer Codeplay Software Ltd. Agenda Default and Deleted Methods Static Assertions Delegated and Inherited Constructors Null

More information

Instantiation of Template class

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

More information

COMP6771 Advanced C++ Programming

COMP6771 Advanced C++ Programming 1.... COMP6771 Advanced C++ Programming Week 5 Part One: Exception Handling 2016 www.cse.unsw.edu.au/ cs6771 2.... Memory Management & Exception Handling.1 Part I: Exception Handling Exception objects

More information

Outline. 1 About the course

Outline. 1 About the course Outline EDAF50 C++ Programming 1. Introduction 1 About the course Sven Gestegård Robertz Computer Science, LTH 2018 2 Presentation of C++ History Introduction Data types and variables 1. Introduction 2/1

More information

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

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

More information

CS11 Advanced C++ Spring 2018 Lecture 2

CS11 Advanced C++ Spring 2018 Lecture 2 CS11 Advanced C++ Spring 2018 Lecture 2 Lab 2: Completing the Vector Last week, got the basic functionality of our Vector template working It is still missing some critical functionality Iterators are

More information

EL2310 Scientific Programming

EL2310 Scientific Programming Lecture 15: Inheritance and Polymorphism, STL (pronobis@kth.se) Overview Overview Lecture 15: Inheritance and Polymorphism, STL Wrap Up Additional Bits about Classes Overloading Inheritance Polymorphism

More information

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

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

More information

Overload Resolution. Ansel Sermersheim & Barbara Geller Amsterdam C++ Group March 2019

Overload 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 information

CPSC 427: Object-Oriented Programming

CPSC 427: Object-Oriented Programming CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 11 October 3, 2018 CPSC 427, Lecture 11, October 3, 2018 1/24 Copying and Assignment Custody of Objects Move Semantics CPSC 427, Lecture

More information

I m sure you have been annoyed at least once by having to type out types like this:

I m sure you have been annoyed at least once by having to type out types like this: Type Inference The first thing I m going to talk about is type inference. C++11 provides mechanisms which make the compiler deduce the types of expressions. These features allow you to make your code more

More information

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

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

More information

C++ Primer. CS 148 Autumn

C++ Primer. CS 148 Autumn C++ Primer CS 148 Autumn 2018-2019 1 Who is this for? If you are taking this class and are not familiar with some of the features of C++, then this guide is for you. In other words, if any of these words

More information

Midterm Review. PIC 10B Spring 2018

Midterm Review. PIC 10B Spring 2018 Midterm Review PIC 10B Spring 2018 Q1 What is size t and when should it be used? A1 size t is an unsigned integer type used for indexing containers and holding the size of a container. It is guarenteed

More information

COEN244: Class & function templates

COEN244: 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 information

Modern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi

Modern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi Modern C++ for Computer Vision and Image Processing Igor Bogoslavskyi Outline Move semantics Classes Operator overloading Making your class copyable Making your class movable Rule of all or nothing Inheritance

More information

Introduction to C++ with content from

Introduction 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 information

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

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

More information

Domains: Move, Copy & Co

Domains: Move, Copy & Co 1 (20) Domains: Move, Copy & Co School of Engineering Sciences Program construction in C++ for Scientific Computing 2 (20) Outline 1 2 3 4 5 3 (20) What Do We Already Have A class hierarchy for constructing

More information

Overload Resolution. Ansel Sermersheim & Barbara Geller ACCU / C++ June 2018

Overload 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 information

Object Oriented Programming. Solved MCQs - Part 2

Object Oriented Programming. Solved MCQs - Part 2 Object Oriented Programming Solved MCQs - Part 2 Object Oriented Programming Solved MCQs - Part 2 It is possible to declare as a friend A member function A global function A class All of the above What

More information

Object-Oriented Programming for Scientific Computing

Object-Oriented Programming for Scientific Computing Object-Oriented Programming for Scientific Computing Dynamic Memory Management Ole Klein Interdisciplinary Center for Scientific Computing Heidelberg University ole.klein@iwr.uni-heidelberg.de 2. Mai 2017

More information

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

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

More information

Advanced 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 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 information

Type Inference auto for Note: Note:

Type Inference auto for Note: Note: Type Inference C++11 provides mechanisms for type inference which make the compiler deduce the types of expressions. I m starting the book with type inference because it can make your code more concise

More information

CS304- Object Oriented Programming LATEST SOLVED MCQS FROM FINALTERM PAPERS. MC

CS304- Object Oriented Programming LATEST SOLVED MCQS FROM FINALTERM PAPERS. MC CS304- Object Oriented Programming LATEST SOLVED MCQS FROM FINALTERM PAPERS JAN 28,2011 MC100401285 Moaaz.pk@gmail.com Mc100401285@gmail.com PSMD01 FINALTERM EXAMINATION 14 Feb, 2011 CS304- Object Oriented

More information

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

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

More information

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

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

More information

A brief introduction to C++

A brief introduction to C++ A brief introduction to C++ Rupert Nash r.nash@epcc.ed.ac.uk 13 June 2018 1 References Bjarne Stroustrup, Programming: Principles and Practice Using C++ (2nd Ed.). Assumes very little but it s long Bjarne

More information

C++ Rvalue References Explained

C++ Rvalue References Explained http://thbecker.net/articles/rvalue_references/section_01.html C++ Rvalue References Explained By Thomas Becker Last updated: March 2013 Contents 1. Introduction 2. Move Semantics 3. Rvalue References

More information

Introduction to C++11 and its use inside Qt

Introduction to C++11 and its use inside Qt Introduction to C++11 and its use inside Qt Olivier Goffart February 2013 1/43 Introduction to C++11 and its use inside Qt About Me http://woboq.com http://code.woboq.org 2/43 Introduction to C++11 and

More information

04-19 Discussion Notes

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

More information

Introduction to C++ Introduction. Structure of a C++ Program. Structure of a C++ Program. C++ widely-used general-purpose programming language

Introduction 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 information

Short Notes of CS201

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

More information

aerix consulting C++11 Library Design Lessons from Boost and the Standard Library

aerix consulting C++11 Library Design Lessons from Boost and the Standard Library C++11 Library Design Lessons from Boost and the Standard Library The Greatest Advice Ever Terry Lahman Eric, every now and then, I m going to come into your office and ask you what you re working on that

More information

Semantics of C++ Hauptseminar im Wintersemester 2009/10 Templates

Semantics 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 information

Tutorial 7. Y. Bernat. Object Oriented Programming 2, Spring Y. Bernat Tutorial 7

Tutorial 7. Y. Bernat. Object Oriented Programming 2, Spring Y. Bernat Tutorial 7 Tutorial 7 Y. Bernat Object Oriented Programming 2, Spring 2016 Exercise 4 STL Outline Part I Today's Topics 1 Exercise 4 2 STL Containers - continue Lambda functions Algorithms Exercise 4 STL Exercise

More information

Copyie Elesion from the C++11 mass. 9 Sep 2016 Pete Williamson

Copyie Elesion from the C++11 mass. 9 Sep 2016 Pete Williamson Copyie Elesion from the C++11 mass 9 Sep 2016 Pete Williamson C++ 11 is a whole new language Links to learning more: http://en.cppreference.com/w/cpp/language/copy_elision https://engdoc.corp.google.com/eng/doc/devguide/cpp/cpp11.shtml?cl=head

More information

Absolute C++ Walter Savitch

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

More information

Qualified std::function signatures

Qualified std::function signatures Document number: P0045R1 Date: 2017 02 06 To: SC22/WG21 LEWG Reply to: David Krauss (david_work at me dot com) Qualified std::function signatures std::function implements type-erasure of the behavior of

More information

CS201 - Introduction to Programming Glossary By

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

More information

Advanced C++ Topics. Alexander Warg, 2017

Advanced 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 information

Overview. 1. Expression Value Categories 2. Rvalue References 3. Templates 4. Miscellaneous Hilarity 2/43

Overview. 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 information

Tokens, Expressions and Control Structures

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

More information

Pointer Basics. Lecture 13 COP 3014 Spring March 28, 2018

Pointer 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 information

COMP6771 Advanced C++ Programming

COMP6771 Advanced C++ Programming 1. COMP6771 Advanced C++ Programming Week 4 Part One: (continued) and 2016 www.cse.unsw.edu.au/ cs6771 2. Inline Constructors, Accessors and Mutators Question (from 2015): In the week 3 examples, constructors

More information

STRUCTURING OF PROGRAM

STRUCTURING OF PROGRAM Unit III MULTIPLE CHOICE QUESTIONS 1. Which of the following is the functionality of Data Abstraction? (a) Reduce Complexity (c) Parallelism Unit III 3.1 (b) Binds together code and data (d) None of the

More information

Modern C++, From the Beginning to the Middle. Ansel Sermersheim & Barbara Geller ACCU / C++ November 2017

Modern C++, From the Beginning to the Middle. Ansel Sermersheim & Barbara Geller ACCU / C++ November 2017 Modern C++, From the Beginning to the Middle Ansel Sermersheim & Barbara Geller ACCU / C++ November 2017 1 Introduction Where is the Beginning Data Types References Const Const Const Semantics Templates

More information

CS304 Object Oriented Programming

CS304 Object Oriented Programming 1 CS304 Object Oriented Programming 1. Which of the following is the way to extract common behaviour and attributes from the given classes and make a separate class of those common behaviours and attributes?

More information

From Java to C++ From Java to C++ CSE250 Lecture Notes Weeks 1 2, part of 3. Kenneth W. Regan University at Buffalo (SUNY) September 10, 2009

From Java to C++ From Java to C++ CSE250 Lecture Notes Weeks 1 2, part of 3. Kenneth W. Regan University at Buffalo (SUNY) September 10, 2009 From Java to C++ CSE250 Lecture Notes Weeks 1 2, part of 3 Kenneth W. Regan University at Buffalo (SUNY) September 10, 2009 C++ Values, References, and Pointers 1 C++ Values, References, and Pointers 2

More information

An Introduction to Template Metaprogramming

An Introduction to Template Metaprogramming An Introduction to Template Metaprogramming Barney Dellar Software Team Lead Toshiba Medical Visualisation Systems Caveat I decided to do this talk after getting thoroughly lost on the recent talk on SFINAE.

More information

Assignment operator string class c++ Assignment operator string class c++.zip

Assignment operator string class c++ Assignment operator string class c++.zip Assignment operator string class c++ Assignment operator string class c++.zip Outside class definitions; Addition assignment: a += b: The binding of operators in C and C++ is specified (character string)

More information

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++ No. of Printed Pages : 3 I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination 05723. June, 2015 BCS-031 : PROGRAMMING IN C ++ Time : 3 hours Maximum Marks : 100 (Weightage 75%)

More information

Database Systems on Modern CPU Architectures

Database Systems on Modern CPU Architectures Database Systems on Modern CPU Architectures Introduction to Modern C++ Moritz Sichert Technische Universität München Department of Informatics Chair of Data Science and Engineering Overview Prerequisites:

More information

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

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

More information

Fast Introduction to Object Oriented Programming and C++

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

More information

Variadic functions: Variadic templates or initializer lists? -- Revision 1

Variadic functions: Variadic templates or initializer lists? -- Revision 1 Variadic functions: Variadic templates or initializer lists? -- Revision 1 Author: Loïc Joly (loic.actarus.joly@numericable.fr ) Document number: N2772=08-0282 Date: 2008-09-17 Project: Programming Language

More information

A Crash Course in (Some of) Modern C++

A Crash Course in (Some of) Modern C++ CMPT 373 Software Development Methods A Crash Course in (Some of) Modern C++ Nick Sumner wsumner@sfu.ca With material from Bjarne Stroustrup & Herb Sutter C++ was complicated/intimidating Pointers Arithmetic

More information

TDDD38 - Advanced programming in C++

TDDD38 - 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 information

l Operators such as =, +, <, can be defined to l The function names are operator followed by the l Otherwise they are like normal member functions:

l Operators such as =, +, <, can be defined to l The function names are operator followed by the l Otherwise they are like normal member functions: Operator Overloading & Templates Week 6 Gaddis: 14.5, 16.2-16.4 CS 5301 Spring 2018 Jill Seaman Operator Overloading l Operators such as =, +,

More information

When we program, we have to deal with errors. Our most basic aim is correctness, but we must

When we program, we have to deal with errors. Our most basic aim is correctness, but we must Chapter 5 Errors When we program, we have to deal with errors. Our most basic aim is correctness, but we must deal with incomplete problem specifications, incomplete programs, and our own errors. When

More information

Engineering Tools III: OOP in C++

Engineering Tools III: OOP in C++ Engineering Tools III: OOP in C++ Engineering Tools III: OOP in C++ Why C++? C++ as a powerful and ubiquitous tool for programming of numerical simulations super-computers (and other number-crunchers)

More information

eingebetteter Systeme

eingebetteter Systeme Praktikum: Entwicklung interaktiver eingebetteter Systeme C++-Tutorial (falk@cs.fau.de) 1 Agenda Classes Pointers and References Functions and Methods Function and Operator Overloading Template Classes

More information

Overview of C Feabhas Ltd 2012

Overview of C Feabhas Ltd 2012 1 2 Copying objects may not be the best solution in many situations. In such cases we typically just want to transfer data from one object to another, rather than make an (expensive, and then discarded)

More information

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity. OOPS Viva Questions 1. What is OOPS? OOPS is abbreviated as Object Oriented Programming system in which programs are considered as a collection of objects. Each object is nothing but an instance of a class.

More information

Cpt S 122 Data Structures. Templates

Cpt S 122 Data Structures. Templates Cpt S 122 Data Structures Templates Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Topics Introduction Function Template Function-template and function-template

More information

Logistics. Templates. Plan for today. Logistics. A quick intro to Templates. A quick intro to Templates. Project. Questions? Introduction to Templates

Logistics. Templates. Plan for today. Logistics. A quick intro to Templates. A quick intro to Templates. Project. Questions? Introduction to Templates Logistics Templates Project Part 1 (clock and design) due Sunday, Sept 25 th Start thinking about partners for Parts 2-3 Questions? Logistics Important date: THURSDAY is Exam 1 Will cover: C++ environment

More information

C++ Primer, Fifth Edition

C++ Primer, Fifth Edition C++ Primer, Fifth Edition Stanley B. Lippman Josée Lajoie Barbara E. Moo Upper Saddle River, NJ Boston Indianapolis San Francisco New York Toronto Montreal London Munich Paris Madrid Capetown Sidney Tokyo

More information

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

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

More information

Appendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things.

Appendix. 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 information

Other C++11/14 features

Other C++11/14 features Other C++11/14 features Auto, decltype Range for Constexpr Enum class Initializer list Default and delete functions Etc. Zoltán Porkoláb: C++11/14 1 Auto, decltype template void printall(const

More information

Object-Oriented Programming, Iouliia Skliarova

Object-Oriented Programming, Iouliia Skliarova Object-Oriented Programming, Iouliia Skliarova A reference (&) is like a constant pointer that is automatically dereferenced. There are certain rules when using references: 1. A reference must be initialized

More information

Modernes C++ Träume und Alpträume

Modernes C++ Träume und Alpträume Modernes Träume und Alpträume Nicolai M. Josuttis 5/17 217 by IT-communication.com 1 Independent consultant continuously learning since 1962 Nicolai M. Josuttis Systems Architect, Technical Manager finance,

More information

IBM Rational Rhapsody TestConductor Add On. Code Coverage Limitations

IBM Rational Rhapsody TestConductor Add On. Code Coverage Limitations IBM Rational Rhapsody TestConductor Add On Code Coverage Limitations 1 Rhapsody IBM Rational Rhapsody TestConductor Add On Code Coverage Limitations Release 2.7.1 2 License Agreement No part of this publication

More information

IS0020 Program Design and Software Tools Midterm, Fall, 2004

IS0020 Program Design and Software Tools Midterm, Fall, 2004 IS0020 Program Design and Software Tools Midterm, Fall, 2004 Name: Instruction There are two parts in this test. The first part contains 22 questions worth 40 points you need to get 20 right to get the

More information

New wording for C++0x Lambdas

New wording for C++0x Lambdas 2009-03-19 Daveed Vandevoorde (daveed@edg.com) New wording for C++0x Lambdas Introduction During the meeting of March 2009 in Summit, a large number of issues relating to C++0x Lambdas were raised and

More information

C++ Important Questions with Answers

C++ 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 information

Expansion statements. Version history. Introduction. Basic usage

Expansion 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 information

CSCI-1200 Data Structures Fall 2018 Lecture 22 Hash Tables, part 2 & Priority Queues, part 1

CSCI-1200 Data Structures Fall 2018 Lecture 22 Hash Tables, part 2 & Priority Queues, part 1 Review from Lecture 21 CSCI-1200 Data Structures Fall 2018 Lecture 22 Hash Tables, part 2 & Priority Queues, part 1 the single most important data structure known to mankind Hash Tables, Hash Functions,

More information