CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2008
    Posts
    3

    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

  2. #2
    Join Date
    Jan 2008
    Location
    India
    Posts
    408

    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

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    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.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Templates compilation

    Quote 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

  5. #5
    Join Date
    Jan 2008
    Location
    India
    Posts
    408

    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
  •  





Click Here to Expand Forum to Full Width

Featured