Last Updated on May 22, 2022 by Admin 3
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("Low"); string n ("End"); a.add(n); //LINE I cout <<a.getValue() <<a.getValue(); //LINE II return 0; }
- compilation error in LINE I
- program outputs:
LowEnd, LowEnd
- program outputs:
LowEnd LowEnd
- program outputs:
LowEndLowEnd
- program outputs:
Low EndLow End