Template Member
///////////////////////////////////////////////////////////////////
// TMember.h: a simple example for demonstrating template members
// Author: Yu Zhang
// Org: Syracuse University
// Contact: 315-314-0228
///////////////////////////////////////////////////////////////////
class TMDemo { //TemplateMemberDemo class
public:
template <typename T>
T DoubleValue(T& ValueRef){return ValueRef*2;}
};
--------------------------------------------------------------------------------------------------
///////////////////////////////////////
// Test_main.cpp: tests package TMember
///////////////////////////////////////
#include "TMember.h"
#include <iostream>
using namespace std;
int main (int argc , char *argv[] )
{
int i = 5;
double j = 5.537;
TMDemo Demo1;
if(argc==2)
if(argv[1][0] == '-'&&argv[1][1]=='V')
cout<<"Instantiating member function for doubling int number:\n";
cout<<Demo1.DoubleValue<int>(i)<<endl;
if(argc==2)
if(argv[1][0] == '-'&&argv[1][1]=='V')
cout<<"Instantiating member function for doubling double number:\n";
cout<<Demo1.DoubleValue<double>(j)<<endl;
return 0;
}
// TMember.h: a simple example for demonstrating template members
// Author: Yu Zhang
// Org: Syracuse University
// Contact: 315-314-0228
///////////////////////////////////////////////////////////////////
class TMDemo { //TemplateMemberDemo class
public:
template <typename T>
T DoubleValue(T& ValueRef){return ValueRef*2;}
};
--------------------------------------------------------------------------------------------------
///////////////////////////////////////
// Test_main.cpp: tests package TMember
///////////////////////////////////////
#include "TMember.h"
#include <iostream>
using namespace std;
int main (int argc , char *argv[] )
{
int i = 5;
double j = 5.537;
TMDemo Demo1;
if(argc==2)
if(argv[1][0] == '-'&&argv[1][1]=='V')
cout<<"Instantiating member function for doubling int number:\n";
cout<<Demo1.DoubleValue<int>(i)<<endl;
if(argc==2)
if(argv[1][0] == '-'&&argv[1][1]=='V')
cout<<"Instantiating member function for doubling double number:\n";
cout<<Demo1.DoubleValue<double>(j)<<endl;
return 0;
}
Comments
Post a Comment