Templates...???

I am an ordinary C programmer and I am most interesed
about dynamical data structuring and programming,
I don't like to use matricess and rows, I like to program
with practical programs that doesent use much memory.
I know a lot of C++ programmers ,and they tolded me,
that C++ templates are real solution for dynamical memory
use programming.I readed 3 books about C++ , but I don't
have a practice and a mass things about templates where
mystery for me I didn't undersrand nothing.
So I will be thankfull if somebody solve with templates
these two programs in end of this post...

Advertisements

On Sat, 10 Sep 2005 01:47:26 +0200, "Bore Biko" <> wrote:
>Dear,
>
>I am an ordinary C programmer and I am most interesed
>about dynamical data structuring and programming,
>I don't like to use matricess and rows, I like to program
>with practical programs that doesent use much memory.
>I know a lot of C++ programmers ,and they tolded me,
>that C++ templates are real solution for dynamical memory
>use programming.I readed 3 books about C++ , but I don't
>have a practice and a mass things about templates where
>mystery for me I didn't undersrand nothing.
>So I will be thankfull if somebody solve with templates
>these two programs in end of this post...

Templates in C++ is just a tool that you can use to solve certain kinds of
problems. The programs that you have included do not belong to that class of
problems and are therefore not likely to benefit from templates.

Templates allow you to program in a style called "generic programming", a
style that lets you use types as a compile-time parameter in your program.

For example, here's a function that adds two numbers:

template <class T>
T add(T a, T b)
{
return a + b;
}

And here's a program that calls it:

int main()
{
double a = add(0.0, 1.0);
int b = add(1, 2);
return 0;
}

The compiler will automatically generate two instances of add(), one that
deals with doubles, and another that deals with ints. In fact, you can pass as
parameters any class that has the operator + defined (and allow access to the
appropriate assignment and copy constructors).

Advertisements

Bore Biko wrote:
> Dear,
>
> I am an ordinary C programmer and I am most interesed
> about dynamical data structuring and programming,
> I don't like to use matricess and rows, I like to program
> with practical programs that doesent use much memory.
> I know a lot of C++ programmers ,and they tolded me,
> that C++ templates are real solution for dynamical memory
> use programming.I readed 3 books about C++ , but I don't
> have a practice and a mass things about templates where
> mystery for me I didn't undersrand nothing.
> So I will be thankfull if somebody solve with templates
> these two programs in end of this post...
>

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!