Learning C++ Templates

Learning C++ Templates

I've found cplusplus.com to be helpful on numerous occasions. Looks like they've got a pretty good intro to templates.

If its an actual book you're looking for, Effective C++ is a classic with a great section on templates.

Learning C++ using a template

The short answer to your question is yes.

The longer answer is yes, BUT you need to consider when to move into the C++ template world. C++ is a very rich languare and comes with enormous power and possibilities. To use this power one needs responsibility and one must have the knowledge to use things wisely. There are many things one needs to understand in C++ in order to write good code and templates is not in the list of most important things.

However, as already mentioned STL (Standard Template Library) is somewhat a central piece in C++ and is, as you see from the name, a library using templates (heavily). In my opinion, STL is something you should start looking at when you start learning C++. For this you will need to understand basic concepts about templates. The same goes for boost, which is a masterpiece in C++ template programming. Here you might need even more understanding what templates are, what they look like and what they do.

My advice is to start by learning the C++ fundamentals without involving templates. This is by itself a big domain and will take a long time to master. When you feel comfortable here, take a look at STL and maybe later boost. Here you can get familiar with template programming as a user of templates in your code. Again, these libraries are big and require work to understand properly so you can use them wisely in your own code.

Here is a nice article about programming in general and what it takes to learn something. C++ is not an exception and requires a lot of time and work.

My own experience in C++ is soon 10 years and I still have a lot to learn, especially about templates. I use them daily, but always try to see when they actually make sence to use. I'm not now talking about using STL or boost, because this I believe is part of my C++ base toolkit. I'm talking about writing my own templated code. What I have seen where I've worked is that people many times have problems with templates and making good software. In my opinion, only a master knows when to be in the template world, when not to and how to combine the two.

Still, templates are very useful and I believe all C++ programmers should have some understanding of them. That level of understanding depends on their own usage of templates and over time you will yourself decide what you use from C++'s huge toolkit.

C++ templates - The Complete Guide is considered the book about templates and is definitely worth a read (or many;)).



Related Topics



Leave a reply



Submit