Module 9
Module 9
Module 9
#include <iostream>
return 0;
}
#include <iostream>
#include <iostream>
return 0;
}
#include <iostream>
return 0;
}
#include <iostream>
#include <iostream>
#include <string>
using namespace std;
T getValue()
{
return value;
}
void add (T _Right)
{
value += _Right;
}
friend ostream & operator<< (ostream & _os, const Pocket < T > &value)
{
_os << value.value;
return _os;
}
};
template <class T > Pocket < T >:: Pocket (T value):value (value)
{
}
int main ()
{
Pocket < string > a ("Hi");
string n ("Tech");
a.add (n); //line i
cout<< a <<", "; //line ii
cout<< a;
return 0;
}
#include <iostream>
#include <string>
using namespace std;
public:
T value; //linei
Pocket (T value):value (value)
{
}
};
int main ()
{
Pocket < double > a (7);
cout<< a.value <<endl; //lineii
return 0;
}
#include <iostream>
#include <string>
using namespace std;
#include <iostream>
#include <string>
using namespace std;
#include <iostream>
#include <string>
using namespace std;
Ty getValue()
{
return value;
}
void add (Ty _Right)
{
value += _Right;
}
template < class Tx > Tx get (Tx _Right)
{
return (Tx) (value) + _Right; //linei
}
friend ostream & operator<< (ostream & _os, const Pocket < Ty > &value)
{
_os << value.value;
return _os;
}
};
template <class T > Pocket < T >:: Pocket (T value):value (value)
{
}
int main ()
{
Pocket < int > a (7);
cout<< a <<", "; //line ii
cout<< a.get <double> (2);
return 0;
}
#include <iostream>
using namespace std;
#include <iostream>
using namespace std;
#include <iostream>
using namespace std;
template < class T> void
f ( T &a)//linei
{
cout << 1 + a << endl;
}
void f (double &a) //line ii
{
cout << 2 + &a << endl;
}
//lineii
int main ()
{
int a = 1.5;
f (a); //lineii
return 0;
}
#include <iostream>
using namespace std;
class SomethingSpecial
{
};
template < typename T > class Pocket
{
T value;
public:
Pocket ()
{
}
Pocket (T value);
T getValue()
{
return value;
}
void add (T _Right)
{
value += _Right;
}
};
template < class T > Pocket < T >:: Pocket (T value):value (value)
{
}
int main ()
{
Pocket < double > a (7); //line i
Pocket < SomethingSpecial > n;
n.add (SomethingSpecial ()); //line ii
cout<< a.getValue () <<", ";
a.add (3);
cout<< a.getValue ();
return 0;
#include <iostream>
using namespace std;
class SomethingSpecial
{
};
template < typename T > class Pocket
{
T value;
public:
Pocket ()
{
}
Pocket (T value);
T getValue()
{
return value;
}
void add (T _Right)
{
value += _Right;
}
};
template < class T > Pocket < T >:: Pocket (T value):value (value)
{
}
int main ()
{
Pocket < string > a ("Hi");
string n ("Maker");
a.add(n); //line i
cout<< a.getValue () <<", ";
a.add (3); //line ii
cout<< a.getValue ();
return 0;
#include <iostream>
using namespace std;
class NothingSpecial
{
};
template < typename T > class Pocket
{
T value; //line i
public:
Pocket ()
{
}
Pocket (T value);
T getValue()
{
return value;
}
void add (T _Right)
{
value += _Right;
}
};
template < class T > Pocket < T >:: Pocket (T value):value (value)
{
}
int main ()
{
Pocket < double > a (7);
Pocket <NothingSpecial>n; //line ii
a.add (3); //line i
cout<< a.getValue () <<", ";
a.add (3); //line ii
cout<< a.getValue ();
return 0;
#include <iostream>
using namespace std;
class SomethingSpecial
{
double value;
public:
Pocket ()
{
}
Pocket (T value);
T getValue()
{
return value;
}
void add (T _Right)
{
value += _Right;
}
};
template < class T > Pocket < T >:: Pocket (T value):value (value)
{
}
int main ()
{
Pocket < double > a (7); //line i
Pocket < SomethingSpecial > n;
n.add (SomethingSpecial ()); //line ii
cout<< a.getValue () <<", ";
a.add (3);
cout<< a.getValue ();
return 0;
#include <iostream>
#include <iostream>