C ++ template specialization, partial specialization test program

#include <iostream>


// specializations template does not add its own constructor and destructor ctor dtor


#if 1
// P1
template <typename T1, typename T2>
class Stack
{
public:
	Stack() { std::cout << "T, T" << std::endl; };
	~Stack() {};

private:

};


#endif // 0


////////////////////////////////////////////////////////////////////

#if 1
// P2
template <typename T1>
class Stack<int, T1>
{
public:
	Stack() { std::cout << "int, T1" << std::endl; };
	~Stack() {};

private:

};

#endif // 0

////////////////////////////////////////////////////////////////////

#if 1
// P3
template <typename T1>
class Stack<T1, int>
{
public:
	Stack() { std::cout << "T1, int" << std::endl; };
	~Stack() {};

private:

};

#endif // 0

////////////////////////////////////////////////////////////////////

#if 0
// P4
template <>
class Stack<int, int>
{
public:
	Stack() { std::cout << "int, int" << std::endl; };
	~Stack() {};

private:

};

//template<>
//inline void Stack<int, int>::p()
//{
//	std::cout << "T, int" << std::endl;
//}
#endif // 0

int main ()
{
								// Call Priority
	Stack<double, double>	s1; // P1
	Stack<float, int>		s2; // P3 > P1
	Stack <int, int> s3; // P4> (P3 or P2, which can not coexist)> P1
	Stack<int, double>		s4; // P2 > P1

}

  

Guess you like

Origin www.cnblogs.com/alexYuin/p/11921840.html