delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/03/07/18:16:53

From: Rodeo Red <rodeored AT netstep DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: explicit instantiation
Date: Mon, 06 Mar 2000 22:57:03 -0500
Organization: Church of Evangelical Environmental Extremism
Lines: 48
Message-ID: <62C1FE9FAA1E4584.06111F9979572068.FEC73EFB7A77FD10@lp.airnews.net>
X-Orig-Message-ID: <38C47E0F DOT 49D97DB2 AT netstep DOT net>
Abuse-Reports-To: support at netstep.net to report improper postings
NNTP-Proxy-Relay: 204.181.96.50
NNTP-Posting-Time: Mon Mar 6 21:52:42 2000
NNTP-Posting-Host: !\s6j-@[.cOZP+F (Encoded at Airnews!)
Mime-Version: 1.0
X-Mailer: Mozilla 4.7 [en] (Win98; I)
X-Accept-Language: en
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Does djgpp support explicit instatation of template functions ? 
This program produces these errors : 

C:\C++\C++PrimerPlus\basic.cpp: In function `int main()':
C:\C++\C++PrimerPlus\basic.cpp:9: parse error before `template'

I have no idea what the parse error could possibly be.  

My books say I can use : 
template  swap <int>(int, int);   
but none of the many books I have give even the slightest hint of a clue
as to where it goes, so I have taken a wild guess. Perhaps it doesn't
matter. I have tried it everywhere but it never works. What is the right
place to put that line ? Why doesn't it work ? 


 #include <iostream>
    using namespace std;
      
template <typename any>
void swap (any &, any &);//template for everything but int


int main()
{   template  swap <int>(int, int);//explicit instantiation for int     
    int first= 10;
    int second=20;
    swap(first, second);   
    
    return 0;
 } 
 
  
    template <typename any>       
    void swap (any &x, any &y)
    {   any temp;
        temp = x;
        x=y;
        y=temp;
     
    }
         


Errors: 

C:\C++\C++PrimerPlus\swap.cpp: In function `int main()':
C:\C++\C++PrimerPlus\swap.cpp:9: parse error before `template'

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019