Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Lecture notes

Lecture notes for lectures 1 - 17

Rating
-
Sold
-
Pages
33
Uploaded on
28-08-2021
Written in
2021/2022

Introduction Domain Modelling Macros Macro hygiene Templates Template specialisation Template metaprogramming AOP AspectJ

Content preview

07 - Templates




Memorize the exact syntax - including defaulting and instantiating

Templates are quite similar to macros – macros are code fragments that are parameterized, which then get
expanded – so are templates. “templates are parameterized declarations”

Templates are very useful in settings like building large websites where there is a need to repeat a lot of code
because some detail varies here and there and templates allow to parameterize this detail and reduce the repetition
of code.

,Functions can also be templated

if the types provided in <> (when using the template) cannot/do not have the operation being used in the template
code there will be compile time error.

,Templates provide parametric polymorphism – important to note that for this type of polymorphism (parametric)
almost no assumptions are made about the parameter i.e. some special implementations or methods

BUT because we know in some cases it will be a class ( <class T> ) some assumptions do get made at that time - such
as copy constructor, destructor, equality operator overloading. Just like in Java when you know it is an object you
can use some calls on the object e.g. .equals

This polymorphism is very similar to the parametric polymorphism in functional languages like Haskell and ML
(where very few assumptions are made about the parameter)

Difference from Haskell – there is no type checking done in C++ template parameters

, Important to note the 3 types of parameters above

When a base type (primitive type) e.g. int is sent into a class type there is auto boxing

You cannot parameterize over local classes

Document information

Uploaded on
August 28, 2021
Number of pages
33
Written in
2021/2022
Type
Lecture notes
Professor(s)
Dr. julian rathke
Contains
All classes
£15.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
darevish

Get to know the seller

Seller avatar
darevish
View profile
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
4 year
Number of followers
0
Documents
1
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Trending documents

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their exams and reviewed by others who've used these revision notes.

Didn't get what you expected? Choose another document

No problem! You can straightaway pick a different document that better suits what you're after.

Pay as you like, start learning straight away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and smashed it. It really can be that simple.”

Alisha Student

Frequently asked questions