Help with Explicit parameter polymorhphism

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2008
Posts: 16
Reputation: vladdy191 is an unknown quantity at this point 
Solved Threads: 0
vladdy191 vladdy191 is offline Offline
Newbie Poster

Help with Explicit parameter polymorhphism

 
0
  #1
Nov 3rd, 2008
So explicit parametric polymorphism need not be restricted to a single type parameter. In other words I can write this in C++
  1. template <typename First, typename Second>
  2. struct Pair
  3. { First f;
  4. Second s;
  5. };

Can someone help me write a funciton "makePair" that takes two paramters of different types and returns a Pair containing its two values?
Hope someone can help
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: Help with Explicit parameter polymorhphism

 
0
  #2
Nov 4th, 2008
have a look at the standard header <utility>. it defines std::pair and std::make_pair.

  1. template <typename First, typename Second>
  2. struct Pair
  3. {
  4. First f;
  5. Second s;
  6. Pair( const First& ff, const Second& ss ) : f(ff), s(ss) {}
  7. // etc
  8. };
  9.  
  10. template <typename First, typename Second> inline
  11. Pair<First,Second> makePair( const First& f, const Second& s )
  12. { return Pair<First,Second>( f, s ) ; }
Reply With Quote Quick reply to this message  
Reply

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



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