What will happen when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
template<class T>
void f(T &a)//LINE I
{
cout << 1 + a << endl;
}
int main()
{
int a = 1;
f(a);//LINE II
return 0;
}
What will happen when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
template<class T>
void f(T &a)//LINE I
{
cout << 1 + a << endl;
}
void f(double &a)//LINE II
{
cout << 2 + a << endl;
}
int main()
{
int a = 1.5;
f(a);//LINE II
return 0;
}
What will happen when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
template<class T>
void f(T &a)//LINE I
{
cout << 1 + a << endl;
}
void f(double &a)//LINE II
{
cout << 2 + a << endl;
}
int main()
{
double a = 1.5;
f(a);//LINE II
return 0;
}
What will happen when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
template<class T>
void f(T &a)//LINE I
{
cout << 1 + a << endl;
}
void f(double &a)
{
cout << 2 + a << endl;
}
int main()
{
double a = 1.5;
f<float &>(a);//LINE II
return 0;
}
What will happen when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
template<class A>
void f(A &a)//LINE I
{
cout << 1 + a << endl;
}
void f(double &a)//LINE II
{
cout << 2 + a << endl;
}
int main()
{
float a = 1.5;
f<float &>(a);//LINE II
return 0;
}
What will happen when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
template <class T>
class Pocket {
T value;//LINE I
public:
Pocket(T value):value(value) {}
};
int main()
{
Pocket<double> a(7);
cout << a.value << endl;//LINE II
return 0;
}
What will happen when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
template <class T>
class Pocket {
public:
T value;//LINE I
Pocket(T value):value(value) {}
};
int main()
{
Pocket<double> a(7);
cout << a.value << endl;//LINE II
return 0;
}
What will happen when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
template <class T>
class Pocket {
public:
T value;
Pocket(T value);
};
template<class T>
Pocket::Pocket(T value):value(value) {}//LINE I
int main()
{
Pocket<double> a(7);//LINE II
cout << a.value << endl;
return 0;
}
What will happen when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
template <class T>
class Pocket {
public:
T value;
Pocket(T value);
};
template<class T>
Pocket<T>::Pocket(T value):value(value) {}//LINE I
int main()
{
Pocket<double> a(7);//LINE II
cout << a.value << endl;
return 0;
}
What will happen when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
template <typedef T>//LINE I
class Pocket {
public:
T value;
Pocket(T value);
};
template<class T>
Pocket<T>::Pocket(T value):value(value) {}//LINE II
int main()
{
Pocket<double> a(7);
cout << a.value << endl;
return 0;
}
What will happen when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
template <typename T>//LINE I
class Pocket {
public:
T value;
Pocket(T value);
};
template<class T>
Pocket<T>::Pocket(T value):value(value) {}//LINE II
int main()
{
Pocket<double> a(7);
cout << a.value << endl;
return 0;
}
What will happen when you attempt to compile and run the following code?
#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) ;
cout << a.getValue() << ", ";
a.add(3) ;
cout << a.getValue();
return 0;
}
What will happen when you attempt to compile and run the following code?
#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;
}
What will happen when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
class SomethingSpecial {
public:
double value;
SomethingSpecial():value(0){}
SomethingSpecial(double value): value(value){}
SomethingSpecial operator+=(SomethingSpecial & _Right) {
SomethingSpecial result;
result.value = value + _Right.value;
return result;
}
};
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;
}
What will happen when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
template <class T>
class Pocket {
T _v;
public:
Pocket() {}
Pocket(T v): _v(v){}
T getV() { return _v; }
void add(T & a) { _v+=a; }
};
int main()
{
Pocket<string> a("Hello");
string s(" world!");
a.add(s);
cout << a.getV() <<endl;
return 0;
}
What will happen when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
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;
}
What will happen when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
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() << ", ";//LINE II
cout << a.getValue();
return 0;
}
What will happen when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
template <typename T>
class Pocket {
T value;
public:
Pocket() {}
Pocket(T value);
T getValue() { return value; }
void add(T _Right) { value += _Right; }
void add(string & _Right){value.insert(0, _Right);}
};
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.getValue() << ", ";//LINE II
cout << a.getValue();
return 0;
}
What will happen when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
template <typename T>
class Pocket {
T value;
public:
Pocket() {}
Pocket(T value);
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;
}
What will happen when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
template <class Ty>
class Pocket {
Ty value;
public:
Pocket() {}
Pocket(Ty value);
Ty getValue() { return value; }
void add(Ty _Right) { value += _Right; }
template <class Tx>
Tx get(Tx _Right) {
return (Tx)(value) + _Right;//LINE I
}
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<string> a("Hi");
string n("Tech");
a.add(n) ;//LINE II
cout << a << ", ";
cout << a.get<double>(1);
return 0;
}
What will happen when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
template <class Ty>
class Pocket {
Ty value;
public:
Pocket() {}
Pocket(Ty value);
Ty getValue() { return value; }
void add(Ty _Right) { value += _Right; }
template <class Tx>
Tx get(Tx _Right) {
return (Tx)(value) + _Right;//LINE I
}
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 << ", ";
cout << a.get<double>(2);
return 0;
}
Which construction/keyword can be used to define the template type parameters? Choose all the correct answers.
template<static T>
Pocket<T>::Pocket(T v):_v(v) {}
template<typedef T>
Pocket<T>::Pocket(T v):_v(v) {}
template<typename T>
Pocket<T>::Pocket(T v):_v(v) {}
template<class T>
Pocket<T>::Pocket(T v):_v(v) {}
template<volatile T>
Pocket<T>::Pocket(T v):_v(v) {}