943,708 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 588
  • C++ RSS
Nov 3rd, 2008
0

Help with Explicit parameter polymorhphism

Expand Post »
So explicit parametric polymorphism need not be restricted to a single type parameter. In other words I can write this in C++
C++ Syntax (Toggle Plain Text)
  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
Reputation Points: 13
Solved Threads: 0
Newbie Poster
vladdy191 is offline Offline
16 posts
since Nov 2008
Nov 4th, 2008
0

Re: Help with Explicit parameter polymorhphism

have a look at the standard header <utility>. it defines std::pair and std::make_pair.

C++ Syntax (Toggle Plain Text)
  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 ) ; }
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: counting a string array
Next Thread in C++ Forum Timeline: helm me please, having trouble with Loop.





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


Follow us on Twitter


© 2011 DaniWeb® LLC