Last Updated on May 22, 2022 by Admin 2
What happen if you try to compile and run this program?
#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; }
- the program outputs
10, 10
- compilation error in LINE II
- the program outputs
10, 13
- compilation error in LINE I
- runtime error at LINE II
- the program outputs
7, 7