-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadjacency.cpp
More file actions
41 lines (39 loc) · 998 Bytes
/
Copy pathadjacency.cpp
File metadata and controls
41 lines (39 loc) · 998 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
#include <iostream>
template <class T = std::size_t>
class Adjacency
{
typedef T Value; //方便外面能够访问这种类型,因为T是不能够在类Adjacency<T>中访问的,所以需要这样写
public:
Adjacency(const Value);
template <class InerType> //支持任意类型的构造函数
Adjacency(InerType v1,int i = 100){};
bool operator<(const Value&) const;
bool operator<=(const Value&) const;
const T data()const;
private:
T data_;
};
template <class T>
Adjacency<T>::Adjacency(const T v):data_(v){};
template <class T>
inline bool Adjacency<T>::operator<(const T& rh) const
{
return data_ < rh.data_;
}
template <class T>
inline bool Adjacency<T>::operator<=(const T& rh) const
{
return data_ < rh.data_;
}
template <class T1>
inline const typename Adjacency<T1>::Value Adjacency<T1>::data() const //typename告诉编译器Adjacency<T1>::Value是一种类型
{
return data_;
}
using namespace std;
int main()
{
Adjacency<> a(10);
Adjacency<> x("123");
return 0;
}