|
-
May 7th, 2008, 01:46 AM
#1
Templates compilation
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
-
May 7th, 2008, 02:07 AM
#2
Re: Templates compilation
its "template" and not "Template" watch the case.
This works
Code:
#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.
Rate the posts which you find useful
-
May 7th, 2008, 02:07 AM
#3
Re: Templates compilation
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.
-
May 7th, 2008, 03:00 AM
#4
Re: Templates compilation
 Originally Posted by ajbharani
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
-
May 7th, 2008, 03:06 AM
#5
Re: Templates compilation
Okie. Thanks, Paul
Rate the posts which you find useful
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|