2008 December 26th Friday
2009-01-02 17:30
387 查看
template <typename T>
template <typename V>
syntax instead of the
template<typename T, typename V>
syntax.
Templates As Parameters
// tempparm.cpp -- template template parameters
#include <iostream>
using namespace std;
#include "stacktp.h"
template <template <typename T> class Thing>
class Crab
{
private:
Thing<int> s1;
Thing<double> s2;
public:
Crab() {};
// assumes the thing class has push() and pop() members
bool push(int a, double x) { return s1.push(a) && s2.push(x); }
bool pop(int & a, double & x){ return s1.pop(a) && s2.pop(x); }
};
int main()
{
Crab<Stack> nebula;
// Stack must match template <typename T> class thing
int ni;
double nb;
while (cin>> ni >> nb && ni > 0 && nb > 0)
{
if (!nebula.push(ni, nb))
break;
}
while (nebula.pop(ni, nb))
cout << ni << ", " << nb << endl;
cout << "Done./n";
return 0;
}
template <typename V>
syntax instead of the
template<typename T, typename V>
syntax.
Templates As Parameters
// tempparm.cpp -- template template parameters
#include <iostream>
using namespace std;
#include "stacktp.h"
template <template <typename T> class Thing>
class Crab
{
private:
Thing<int> s1;
Thing<double> s2;
public:
Crab() {};
// assumes the thing class has push() and pop() members
bool push(int a, double x) { return s1.push(a) && s2.push(x); }
bool pop(int & a, double & x){ return s1.pop(a) && s2.pop(x); }
};
int main()
{
Crab<Stack> nebula;
// Stack must match template <typename T> class thing
int ni;
double nb;
while (cin>> ni >> nb && ni > 0 && nb > 0)
{
if (!nebula.push(ni, nb))
break;
}
while (nebula.pop(ni, nb))
cout << ni << ", " << nb << endl;
cout << "Done./n";
return 0;
}
相关文章推荐
- 2008 December 12th Friday
- 2008 September 26th Friday (九月 二十六日 金曜日)
- 2008 December 19th Friday
- 2008 April 18th Friday (四月 十八日 金曜日)
- 2008 May 26th Monday (五月 二十六日 月曜日)
- 2008 July 4th Friday (七月 四日 金曜日)
- 2008 September 5th Friday (九月 五日 金曜日)
- October 26th Friday (十月 二十六日 金曜日)
- 2008 December 23th Tuesday
- 2008 February 1st Friday (二月 一日 金曜日)
- 2008 February 15th Friday (二月 十五日 金曜日)
- 2008 February 26th Tuesday (二月 二十六日 火曜日)
- 2008 March 7th Friday (三月 七日 金曜日)
- 2008 August 1st Friday (八月 一日 金曜日)
- 2008 October 24th Friday (十月 二十四日 金曜日)
- December 26th Wednesday (十二月 二十六日 水曜日)
- December 4th Friday 2009
- 2008 December 11th Thursday
- 2008 December 25th Thursday
- December 2008