Click to See Complete Forum and Search --> : Templates compilation


venkyomni
May 7th, 2008, 01:46 AM
Hi, I am a beginner programmer in C++, encountering a compiling issue when i tried to debug a program related to the templates..
Brief code is
Template <class x> void my function( x a, x b)
{
//body
}

when i wrote this code and complied , getting an error saying " type name missing"

Do I have to use a latest compiler for this or is ther some other issue in it like have to add any include libraries...

Thanks
venkat

ajbharani
May 7th, 2008, 02:07 AM
its "template" and not "Template" watch the case.
This works

#include<iostream.h>

template <class T> T Add(T x,T y)
{
return (x+y);
}

int main()
{
cout<<Add(12,13)<<endl;
return 0;
}

Bharani.

cilu
May 7th, 2008, 02:07 AM
1. C++ is a case-sensitive language, so it should be 'template' not 'Template'.
2. names in any programming language cannot include space as in 'my function'. it should be myfunction or my_function.

Paul McKenzie
May 7th, 2008, 03:00 AM
This works

Not on the compiler that I use or many ANSI standard compiler. The correct standard header is <iostream>, not <iostream.h>

Regards,

Paul McKenzie

ajbharani
May 7th, 2008, 03:06 AM
Okie. Thanks, Paul :)