Last active
August 14, 2018 12:09
-
-
Save 1f0/d5a1d44a5e5f40580cb34b88982b3030 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
template<typename T, typename N> | |
class Test | |
{ | |
public: | |
Test( T i, N j ) : a(i), b(j) | |
{ | |
cout<<"普通模板类"<< a <<' ' << b << endl; | |
} | |
private: | |
T a; | |
N b; | |
}; | |
template<> | |
class Test<int , char> | |
{ | |
public: | |
Test( int i, char j ) : a( i ), b( j ) | |
{ | |
cout<<"模版类全特化"<< a << ' ' << b << endl; | |
} | |
private: | |
int a; | |
char b; | |
}; | |
template <typename N> | |
class Test<int, N> | |
{ | |
public: | |
Test( int i, N j ):a( i ), b( j ) | |
{ | |
cout<<"模版类偏特化"<< a<< ' ' << b << endl; | |
} | |
private: | |
int a; | |
N b; | |
}; | |
int main() | |
{ | |
Test<double , double> t1( 0.1,0.2 ); //普通模版类 | |
Test<int , char> t2( 1, 'A' ); //模版类完全特化 | |
Test<int, bool> t3( 1, true ); //模版类偏特化 | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment