Can Templates Have prototypes ?

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Mar 2007
Posts: 55
Reputation: addicted is an unknown quantity at this point 
Solved Threads: 0
addicted's Avatar
addicted addicted is offline Offline
Junior Poster in Training

Can Templates Have prototypes ?

 
0
  #1
Apr 20th, 2007
If yes,
Help with the declaration
00110101
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,089
Reputation: vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all 
Solved Threads: 164
vijayan121 vijayan121 is offline Offline
Veteran Poster

Re: Can Templates Have prototypes ?

 
0
  #2
Apr 20th, 2007
Originally Posted by addicted View Post
If yes,
Help with the declaration
  1. template< typename T > inline void swap( T& a, T& b ) ; // declaration (function)
  2. template< typename T, size_t N > struct array ; // declaration (class)
  3.  
  4. // definition of function
  5. template< typename T > void swap( T& a, T& b )
  6. { T temp(a) ; a=b ; b=temp ; }
  7.  
  8. // definition of class
  9. template< typename T, size_t N > struct array
  10. {
  11. T& operator[] ( size_t i )
  12. {
  13. if( i >= N ) throw "array bound exceeded!" ;
  14. return a[i] ;
  15. }
  16.  
  17. const T& operator[] ( size_t i ) const
  18. {
  19. if( i >= N ) throw "array bound exceeded!" ;
  20. return a[i] ;
  21. }
  22.  
  23. private: T a[N] ;
  24. };
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC