Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Introduction to C++ Templates | Creating First Template
C++ Templates

bookIntroduction to C++ Templates

How to turn this in a single function?

In this course, you'll learn how to use templates in various scenarios and write concise, scalable code. For example, you'll discover how to create a single function that can replace multiple ones and it is only the tip of the iceberg.

functions.h

functions.h

copy
12345
int add(int a, int b) { return a + b; } float add(float a, float b) { return a + b; } std::string add(std::string a, std::string b) { return a + b; }
template.h

template.h

copy
12
template<typename T> T add(T a, T b) { return a + b; }
question mark

Are you ready to start learning templates?

Select the correct answer

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 1. Kapitel 1

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

Awesome!

Completion rate improved to 5.88

bookIntroduction to C++ Templates

Stryg for at vise menuen

How to turn this in a single function?

In this course, you'll learn how to use templates in various scenarios and write concise, scalable code. For example, you'll discover how to create a single function that can replace multiple ones and it is only the tip of the iceberg.

functions.h

functions.h

copy
12345
int add(int a, int b) { return a + b; } float add(float a, float b) { return a + b; } std::string add(std::string a, std::string b) { return a + b; }
template.h

template.h

copy
12
template<typename T> T add(T a, T b) { return a + b; }
question mark

Are you ready to start learning templates?

Select the correct answer

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 1. Kapitel 1
some-alt