Hm.. I read the template tutorial on this site and so I think I kinda understand templates, but I'd like to know why they are used?
What sort of things have you guys used templates for around here?
~ Paul
Hm.. I read the template tutorial on this site and so I think I kinda understand templates, but I'd like to know why they are used?
What sort of things have you guys used templates for around here?
~ Paul
containers usually.
Imagine you've just created your first stack class which handles integers. Now you've been asked to wirte one for for char's, strings, and 3 other classes that you've already defined. If you made your stack a template class then you can already use it for the chars, and provided your user defined classes have the right operators overloaded, they should be fine to use as well.
So you don't have to rewrite the same code for different datatypes.Originally posted by stovellp
Hm.. I read the template tutorial on this site and so I think I kinda understand templates, but I'd like to know why they are used?
I've made a linked list template (see my homepage). This has been of real use for me in every program that uses lists. No need to spend time on writing it every time from now on .Originally posted by stovellp
What sort of things have you guys used templates for around here?
Oh, and it has a buildt-in iterator in it if you need to do something to all the nodes.
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
Wow, I guess your quite right there.. Whats a stack?
~ Paul
Imagine a pile of dirty plates. One person puts their plate down. Then, another person comes and puts their dirty plate on top. And so on, and so on. Which is the first one washed? The last one put on top of course. This is what a stack is. It is known as FILO (First In Last Out).
Just being nitpicky, but it is actually LIFO (Last In First Out).Originally posted by golfinguy4
Imagine a pile of dirty plates. One person puts their plate down. Then, another person comes and puts their dirty plate on top. And so on, and so on. Which is the first one washed? The last one put on top of course. This is what a stack is. It is known as FILO (First In Last Out).