C ++ exercise note _ 2

Source: Internet
Author: User
C ++ exercise note _ 2

I'm playing soy sauce, Don't look...

// 2010/11/19 // Zephyr // Template Test # include <iostream> using namespace std; # define MyWord "traps everywhere" // real template <typename my> void SetVal (my & ori) {ori ++ = ori;} template <typename T1, typename T2> void MulVal (T1 & ori, T2 count) {ori * = count;} template <typename T, typename T2> class MyTemp {private: T m_Val; T2 m_Val2; public: MyTemp (T val, T2 val2) {m_Val = val; m_Val2 = val2;} T GetVal () ;}; template <typename T, typenam E T2> T MyTemp <T, T2 >:: GetVal () {return m_Val;} void main () {MyTemp <int, unsigned char> new1 (10,128 ); myTemp <double, string> new2 (168.6451, string ("What's up? "); Cout <new1.GetVal () <endl; cout <new2.GetVal () <endl; int t1 = 10; double t2 = 16.6; SetVal (t1 ); setVal (t2); cout <t1 <endl <t2 <endl; MulVal (t2, t1); cout <t2 <endl; cout <MyWord <endl; system ("pause ");}
ps:
With this LiveWriter, you can finally get rid of the painful image problems ~~~
Put two FF pictures for encouragement:
  
 
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.