-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.cpp
More file actions
51 lines (48 loc) · 893 Bytes
/
template.cpp
File metadata and controls
51 lines (48 loc) · 893 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<iostream>
using namespace std;
template <class T1,class T2>
class AAA
{
private:
T1 x;
T2 y;
public:
AAA(T1 a, T2 b) {x = a; y = b;}
void myShow()
{
cout<< (x>y?x:y)<<endl;
}
};
void main()
{
int a=1;
float b = 2.0;
(++a)+=(a++);
a = 1;
a+= (a++);
AAA<int,float> m(a,b);
m.myShow();
}
/*
#include <iostream>
using namespace std;
template <class T1, class T2> //使用2个类型参数
class MyTemClass //定义类模板
{
private:
T1 x;
T2 y;
public:
MyTemClass(T1 a, T2 b) {x=a; y=b;} //构造函数
void ShowMax() //输出最大的数据成员
{
cout<<"MaxMember="<<(x>=y ? x : y)<<endl;
}
};
void main()
{
int a=100;
float b=123.45F;
MyTemClass<int, float> mt(a,b); //声明类模板的对象
mt.ShowMax();
} */