943,989 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 918
  • C RSS
Apr 20th, 2007
0

Can Templates Have prototypes ?

Expand Post »
If yes,
Help with the declaration
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
addicted is offline Offline
57 posts
since Mar 2007
Apr 20th, 2007
0

Re: Can Templates Have prototypes ?

Click to Expand / Collapse  Quote originally posted by addicted ...
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. };
Reputation Points: 1159
Solved Threads: 285
Posting Virtuoso
vijayan121 is offline Offline
1,606 posts
since Dec 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Frequency Counter
Next Thread in C Forum Timeline: Hospital Record.. double array.. help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC