Home » C++ Programming » Templates » Question
  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    template<typename type>
    class Example
    {
    public:
    Example()
    {
    };
    ~Example()
    {
    };
    Example FunctionA(Example num1)
    {
    return num1;
    }
    Example FunctionB(Example num2)
    {
    return num2;
    }
    };
    int main()
    {
    Test<int> num1;
    Test<float> num2;
    cout << num1.FunctionA(150) << endl;
    cout << num2.FunctionB(2.125) << endl;
    return 0;
    }
    1. 150
    2. 2.125
    3. 2.125
      150
    4. 150
      2.125
    5. Compilation Error
Correct Option: D

In this program, We are passing the values and getting it back from template. And we are using the constructor and destructor for the function template.



Your comments will be displayed only after manual approval.