模板基础1

//test.h

#pragma once
#include <iostream>
#include <vector>
#include <string>
#include <conio.h>
#include <atlstr.h>//CString


using namespace std;

template <class typeIP,class typePort>
class CTest
{
public:
 CTest(void){};
 ~CTest(void){};
private:
 vector<typeIP> ip;
 vector<typePort> port;
};
//t1.cpp

#include <iostream>
#include <vector>
#include <string>
#include <conio.h>
#include <atlstr.h>//CString
#include "h.h"
#include "Test.h"
using namespace std;

template <typename type1> void Print(vector<type1> &str);
template <typename type2> void Print(vector<type2> &);
void main()
{
 vector<string> v_str;
 v_str.push_back("aa");
 v_str.push_back("bb");
 v_str.push_back("cc");
 Print(v_str);

 vector<int> v_int;
 v_int.push_back(11);
 v_int.push_back(22);
 v_int.push_back(33);
 Print(v_int);

 CTest<string,int> myClass;
 getch();


}


template <typename type3> inline void Print(vector<type3> &str)
{
 vector<type3>::iterator vit_p;
 for (vit_p = str.begin(); vit_p!=str.end(); vit_p++)
 {
  cout<<(*vit_p)<<"  ";
 }
 cout<<endl;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值